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

时间:2014-02-02 21:37:53

标签: java swing jframe jpanel jbutton

经过多次尝试简化我的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(

0 个答案:

没有答案