Java 灰色的jframe是关于什么的。它在工作,现在不行吗?

Java 灰色的jframe是关于什么的。它在工作,现在不行吗?,java,swing,jframe,jpanel,jbutton,Java,Swing,Jframe,Jpanel,Jbutton,在多次尝试简化我的Dopewars项目之后,我终于通过了我也完成的前一个阶段。突然,我运行我的应用程序,一个灰色的框出现了。我没有做过这种颜色的面板,所以我不知道我的问题出在哪里 我想知道是否有人能把它推倒,甚至指出我的错在哪里。任何帮助都将不胜感激。提前谢谢 package hhh; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

在多次尝试简化我的Dopewars项目之后,我终于通过了我也完成的前一个阶段。突然,我运行我的应用程序,一个灰色的框出现了。我没有做过这种颜色的面板,所以我不知道我的问题出在哪里

我想知道是否有人能把它推倒,甚至指出我的错在哪里。任何帮助都将不胜感激。提前谢谢

    package hhh;



import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Random;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;



public class Gui implements ActionListener {



JButton travels, traveltoengland, traveltofrance, traveltogermany, traveltospain, traveltoitaly, traveltoukraine, traveltopoland;

JButton traveltonewyork, traveltocalifornia, traveltoflorida, traveltotexas, traveltowashington, traveltoillinois;

JButton traveltocolumbia, traveltovenezuela, traveltobrazil, traveltoargentina, traveltochile;



JPanel travel, england, france, germany, spain, italy, ukraine, poland;



JLabel englandvalue1;

JLabel francevalue1;

JLabel germanyvalue1;

JLabel spainvalue1;

JLabel italyvalue1;

JLabel ukrainevalue1;

JLabel polandvalue1;



JButton finances;

JPanel finance;



JButton investments;

JPanel investment;



public Gui(){

    JFrame f = new JFrame();

    f.setSize(700, 500);

    f.setLayout(null);

    f.setLocationRelativeTo(null);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setVisible(true);



    JPanel bg = new JPanel();

    bg.setSize(700, 500);

    bg.setBackground(Color.darkGray);

    bg.setLayout(null);



    JPanel s = new JPanel();

    s.setSize(200, 500);

    s.setBackground(Color.red);

    s.setLayout(null);



    travels = new JButton("Travel");

    travels.setSize(150, 30);

    travels.setLocation(210, 10);

    travels.addActionListener(this);



    finances = new JButton("Finance");

    finances.setSize(152, 30);

    finances.setLocation(370, 10);

    finances.addActionListener(this);



    investments = new JButton("Investment");

    investments.setSize(150, 30);

    investments.setLocation(532, 10);

    investments.addActionListener(this);



    travel = new JPanel();

    travel.setSize(472, 405);

    travel.setLocation(210, 50);

    travel.setBackground(Color.lightGray);

    travel.setLayout(null);

    travel.setVisible(false);



    finance = new JPanel();

    finance.setSize(472, 405);

    finance.setLocation(210, 50);

    finance.setBackground(Color.magenta);

    finance.setLayout(null);

    finance.setVisible(false);



    investment = new JPanel();

    investment.setSize(472, 405);

    investment.setLocation(210, 50);

    investment.setBackground(Color.yellow);

    investment.setLayout(null);

    investment.setVisible(false);



    JLabel europe = new JLabel("Europe:");

    europe.setSize(100, 20);

    europe.setLocation(10, 10);

    europe.setFont(europe.getFont().deriveFont(16.0f));



    traveltoengland = new JButton("England");

    traveltoengland.setSize(105, 20);

    traveltoengland.setLocation(10, 40);

    traveltoengland.addActionListener(this);

    traveltoengland.setFont(traveltoengland.getFont().deriveFont(11.0f));



    traveltofrance = new JButton("France");

    traveltofrance.setSize(105, 20);

    traveltofrance.setLocation(125, 40);

    traveltofrance.addActionListener(this);

    traveltofrance.setFont(traveltofrance.getFont().deriveFont(11.0f));



    traveltogermany = new JButton("Germany");

    traveltogermany.setSize(105, 20);

    traveltogermany.setLocation(240, 40);

    traveltogermany.addActionListener(this);

    traveltogermany.setFont(traveltogermany.getFont().deriveFont(11.0f));



    traveltospain = new JButton("Spain");

    traveltospain.setSize(105, 20);

    traveltospain.setLocation(355, 40);

    traveltospain.addActionListener(this);

    traveltospain.setFont(traveltospain.getFont().deriveFont(11.0f));



    traveltoitaly = new JButton("Italy");

    traveltoitaly.setSize(105, 20);

    traveltoitaly.setLocation(10, 70);

    traveltoitaly.addActionListener(this);

    traveltoitaly.setFont(traveltoitaly.getFont().deriveFont(11.0f));



    traveltoukraine = new JButton("Ukraine");

    traveltoukraine.setSize(105, 20);

    traveltoukraine.setLocation(125, 70);

    traveltoukraine.addActionListener(this);

    traveltoukraine.setFont(traveltofrance.getFont().deriveFont(11.0f));



    traveltopoland = new JButton("Poland");

    traveltopoland.setSize(105, 20);

    traveltopoland.setLocation(240, 70);

    traveltopoland.addActionListener(this);

    traveltopoland.setFont(traveltogermany.getFont().deriveFont(11.0f));



    JLabel america = new JLabel("N.America:");

    america.setSize(100, 20);

    america.setLocation(10, 120);

    america.setFont(america.getFont().deriveFont(16.0f));



    traveltonewyork = new JButton("New York");

    traveltonewyork.setSize(105, 20);

    traveltonewyork.setLocation(10, 150);

    traveltonewyork.addActionListener(this);

    traveltonewyork.setFont(traveltonewyork.getFont().deriveFont(11.0f));



    traveltocalifornia = new JButton("California");

    traveltocalifornia.setSize(105, 20);

    traveltocalifornia.setLocation(125, 150);

    traveltocalifornia.addActionListener(this);

    traveltocalifornia.setFont(traveltocalifornia.getFont().deriveFont(11.0f));



    traveltoflorida = new JButton("Chicago");

    traveltoflorida.setSize(105, 20);

    traveltoflorida.setLocation(240, 150);

    traveltoflorida.addActionListener(this);

    traveltoflorida.setFont(traveltoflorida.getFont().deriveFont(11.0f));



    traveltotexas = new JButton("Texas");

    traveltotexas.setSize(105, 20);

    traveltotexas.setLocation(355, 150);

    traveltotexas.addActionListener(this);

    traveltotexas.setFont(traveltotexas.getFont().deriveFont(11.0f));



    traveltowashington = new JButton("Washington");

    traveltowashington.setSize(105, 20);

    traveltowashington.setLocation(10, 180);

    traveltowashington.addActionListener(this);

    traveltowashington.setFont(traveltowashington.getFont().deriveFont(11.0f));



    traveltoillinois = new JButton("Illinois");

    traveltoillinois.setSize(105, 20);

    traveltoillinois.setLocation(120, 180);

    traveltoillinois.addActionListener(this);

    traveltoillinois.setFont(traveltoillinois.getFont().deriveFont(11.0f));



    JLabel samerica = new JLabel("S.America:");

    samerica.setSize(100, 20);

    samerica.setLocation(10, 230);

    samerica.setFont(america.getFont().deriveFont(16.0f));



    traveltocolumbia = new JButton("Columbia");

    traveltocolumbia.setSize(105, 20);

    traveltocolumbia.setLocation(10, 260);

    traveltocolumbia.addActionListener(this);

    traveltocolumbia.setFont(traveltocolumbia.getFont().deriveFont(11.0f));



    traveltovenezuela = new JButton("Venezuela");

    traveltovenezuela.setSize(105, 20);

    traveltovenezuela.setLocation(125, 260);

    traveltovenezuela.addActionListener(this);

    traveltovenezuela.setFont(traveltovenezuela.getFont().deriveFont(11.0f));



    traveltobrazil = new JButton("Brazil");

    traveltobrazil.setSize(105, 20);

    traveltobrazil.setLocation(240, 260);

    traveltobrazil.addActionListener(this);

    traveltobrazil.setFont(traveltobrazil.getFont().deriveFont(11.0f));



    traveltoargentina = new JButton("Argentina");

    traveltoargentina.setSize(105, 20);

    traveltoargentina.setLocation(355, 260);

    traveltoargentina.addActionListener(this);

    traveltoargentina.setFont(traveltoargentina.getFont().deriveFont(11.0f));



    traveltochile = new JButton("Chile");

    traveltochile.setSize(105, 20);

    traveltochile.setLocation(10, 290);

    traveltochile.addActionListener(this);

    traveltochile.setFont(traveltochile.getFont().deriveFont(11.0f));



    england = new JPanel();

    england.setSize(472, 405);

    england.setLocation(210, 50);

    england.setBackground(Color.green);

    england.setLayout(null);

    england.setVisible(false);



    englandvalue1 = new JLabel();

    englandvalue1.setSize(100, 30);

    englandvalue1.setLocation(10, 10);



    france = new JPanel();

    france.setSize(472, 405);

    france.setLocation(210, 50);
    france.setBackground(

请编辑您的问题,以包括一个格式正确的问题,展示您所描述的问题。您实际上没有添加任何内容<代码>设置位置不添加它。还要学习使用布局管理器。避免使用空布局谢谢进行编辑,我是通过一部手机写的,这部手机播放效果不好,很抱歉给您带来不便。@peeskillet-当您说“它”时,您指的是哪个组件?我在Gui()的底部添加了.all my components.Java Gui,它可能需要在多种平台上工作,使用不同的屏幕分辨率&使用不同的plaf。因此,它们不利于部件的精确放置。要为健壮的GUI组织组件,请改为使用布局管理器,或者与布局填充和边框一起使用。