0

After many attempts of simplifying my Dopewars project, I have finally passed the previous stage I had made it too. all of a sudden I ran my application and a grey box has appeared. I havent made any panels in this colour so I dont know where my problem may lay.

i was.wondering if somebody could run it over, or even point out where I am at fault. Any help would be greatly appreciated. Thanks in advance.

    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(
shortCircuit
  • 169
  • 2
  • 10
dazbrad
  • 182
  • 1
  • 12
  • Please edit your question to include a properly formatted [mcve](http://stackoverflow.com/help/mcve) that exhibits the problem you describe. – trashgod Feb 02 '14 at 21:40
  • You haven't actually added anything. `setLocation` doesn't add it. Also learn to use layout managers. Avoid using null layouts – Paul Samsotha Feb 02 '14 at 21:51
  • Thanks for the edit, Im writing this via a mobile phone which isnt playing nicely, sorry for the inconvenience. – dazbrad Feb 02 '14 at 21:52
  • @peeskillet - when you say "it", which component are you talking about? I have added.all my components.at the bottom of Gui(). – dazbrad Feb 02 '14 at 21:55
  • Also, why do null layouts effect the project. Someone I spoke.to said this but didnt explain too well. Thanks – dazbrad Feb 02 '14 at 21:58
  • 2
    Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Feb 02 '14 at 23:15
  • I hve .always avoided using anything other than null layouts because as far as the code goes, it looks much more understandable and easier on the eye (each component explicitly defined in logical sections) for me to learn. However, the examples shown in your link do look very.good, and also now that I hve seen a gd example, layout managers do look quite tidy and managable. – dazbrad Feb 03 '14 at 10:01
  • Would the use of a.layout manager also fix this grey screen problem I have currenly? – dazbrad Feb 03 '14 at 10:05

0 Answers0