Results 1 to 4 of 4
- 06-08-2012, 04:57 AM #1
Member
- Join Date
- May 2012
- Posts
- 6
- Rep Power
- 0
jbuttons and jcombobox didn't show up please help...
Hey guys, there are two separated questions in this thread
1) The jbuttons or jcombobox didn't show up in my GUI even though I added both of them in my frame. There's no error for this code, just that it doesn't show up in GUI.
2) Do you guys have any open-source for AI-chess? I need it for my current project I tried all the best I could to find an open-source that contains easy,medium,hard but couldn't find any that works with java...
Thanks alot :).Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Calendar; import java.util.Calendar; public class chess extends JFrame{ int x = 0; //texts or labels or panels private JLabel label1,label2,label3,label4,difficulties,statusbar; private JTextField timeF,timeT; private JPanel panel,panel1,panel2,panel3,panel4; //buttons private JButton start,stop,settings, aminutes, bminutes, cminutes, dcustom; //combo boxes private JComboBox difficulty, color; //j frame private JFrame frame; //lsits for combobox private static String[] difflist = {"Easy", "Medium", "Hard"}; private static String[] colorlist = {"White", "Black"}; //for timer public chess (){ //house keeping stuffs JFrame frame = new JFrame("Chess"); frame.setSize(900,900); frame.setVisible(true); frame.setResizable(true); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);; JPanel panel1 = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); frame.add(panel1, BorderLayout.CENTER); Font f = new Font("sansserif", Font.BOLD, 15); label1 = new JLabel("Difficulties : "); label1.setFont(f); label2 = new JLabel("Colour : "); label2.setFont(f); label3 = new JLabel("Black User's Timer : "); label3.setFont(f); label4 = new JLabel("White User's Timer : "); label4.setFont(f); c.insets = new Insets(100,100,800,800); c.gridx = 0; c.gridy = 0; panel1.add(label1,c); c.insets = new Insets(100,72,700,800); c.gridx = 0; c.gridy = 0; panel1.add(label2, c); c.anchor = GridBagConstraints.PAGE_END; c.insets = new Insets(0,0,400,0); c.gridx = 0; c.gridy = 0; panel1.add(label3, c); c.anchor = GridBagConstraints.PAGE_END; c.insets = new Insets(0,0,200,0); c.gridx = 0; c.gridy = 0; panel1.add(label4, c); JComboBox diff = new JComboBox(difflist); JComboBox color = new JComboBox(colorlist); c.insets = new Insets(100,100,800,600); c.gridx = 30; c.gridy = 30; panel1.add(diff, c); frame.add(panel1); c.insets = new Insets(10,0,0,0); c.gridx = 1; c.gridy = 2; panel1.add(color, c); statusbar = new JLabel("Status Bar Current State: Default"); JLabel statusbar = new JLabel(); statusbar.setFont(new Font("Arial",Font.BOLD,25)); JButton start = new JButton("Start"); JButton stop = new JButton("Stop"); JButton settings = new JButton("Settings"); c.insets = new Insets(100,100,400,800); c.gridx = 10; c.gridy = 10; panel1.add(start, c); c.insets = new Insets(10,0,0,0); c.gridx = 1; c.gridy = 2; panel1.add(color, c); } }
- 06-08-2012, 06:49 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: jbuttons and jcombobox didn't show up please help...
Read the API for Container: Container (Java Platform SE 6)
Unless you have a specific reason, add the components to a container prior to setting it to visible. In your case, there is no reason to immediately set the JFrame to visible until all components have been added.
- 06-08-2012, 04:37 PM #3
Member
- Join Date
- May 2012
- Posts
- 6
- Rep Power
- 0
Re: jbuttons and jcombobox didn't show up please help...
sorry.. i didn't really understand what you meant but yeah i only set the visible at the end after I have added all my components still the combobox/button doesn't show up...
can
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Calendar; import java.util.Calendar; public class chess extends JFrame{ int x = 0; //texts or labels or panels private JLabel label1,label2,label3,label4,difficulties,statusbar; private JTextField timeF,timeT; private JPanel panel,panel1,panel2,panel3,panel4; //buttons private JButton start,stop,settings, aminutes, bminutes, cminutes, dcustom; //combo boxes private JComboBox difficulty, color; //j frame private JFrame frame; //lsits for combobox private static String[] difflist = {"Easy", "Medium", "Hard"}; private static String[] colorlist = {"White", "Black"}; //for timer public chess (){ //house keeping stuffs JFrame frame = new JFrame("Chess"); frame.setSize(900,900); frame.setVisible(true); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);; JPanel panel1 = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); frame.add(panel1, BorderLayout.CENTER); statusbar = new JLabel("Status Bar Current State: Default"); c.insets = new Insets(100,72,700,800); c.gridx = 0; c.gridy = 0; Font f = new Font("sansserif", Font.BOLD, 15); label1 = new JLabel("Difficulties : "); label1.setFont(f); label2 = new JLabel("Colour : "); label2.setFont(f); label3 = new JLabel("Black User's Timer : "); label3.setFont(f); label4 = new JLabel("White User's Timer : "); label4.setFont(f); c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(100,100,800,800); c.gridx = 0; c.gridy = 0; panel1.add(label1,c); c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(100,72,700,800); c.gridx = 0; c.gridy = 0; panel1.add(label2, c); c.anchor = GridBagConstraints.PAGE_END; c.insets = new Insets(0,0,400,0); c.gridx = 0; c.gridy = 0; panel1.add(label3, c); c.anchor = GridBagConstraints.PAGE_END; c.insets = new Insets(0,0,200,0); c.gridx = 0; c.gridy = 0; panel1.add(label4, c); JComboBox diff = new JComboBox(difflist); JComboBox color = new JComboBox(colorlist); c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(100,100,800,600); c.gridx = 30; c.gridy = 30; panel1.add(diff, c); frame.add(panel1); c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10,0,0,0); c.gridx = 1; c.gridy = 2; panel1.add(color, c); statusbar = new JLabel("Status Bar Current State: Default"); JLabel statusbar = new JLabel(); statusbar.setFont(new Font("Arial",Font.BOLD,25)); JButton start = new JButton("Start"); JButton stop = new JButton("Stop"); JButton settings = new JButton("Settings"); c.insets = new Insets(100,100,400,800); c.gridx = 10; c.gridy = 10; panel1.add(start, c); c.insets = new Insets(10,0,0,0); c.gridx = 1; c.gridy = 2; panel1.add(color, c); //timer timeF = new JTextField(10); timeF.setEditable(false); timeF.setFont(new Font("Arial",Font.PLAIN,48)); Timer t = new Timer(1000, new Listener()); t.start(); c.gridx = 0; c.gridy = 0; panel2.add(label3, c); frame.setResizable(true); } class Listener implements ActionListener{ public void actionPerformed(ActionEvent e){ Font font = new Font("SansSerif",Font.BOLD,20); timeF.setText(x+""); timeF.setBackground(Color.BLACK); timeF.setForeground(Color.GREEN); timeF.setFont(font); x++; } } } /* frame.setVisible(true); frame.setResizable(true); frame.setLocationRelativeTo(null);*/
- 06-08-2012, 04:48 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
The code didn't delete the text file
By amyng in forum New To JavaReplies: 3Last Post: 05-01-2012, 06:37 AM -
class contains constructor with one variable, driver code didn't work, ask for help!
By myloveca in forum New To JavaReplies: 0Last Post: 02-27-2012, 10:29 PM -
NetBeans Didn't show the Design mode
By ryor310575 in forum NetBeansReplies: 2Last Post: 05-31-2011, 06:48 AM -
my JButtons won't show up
By gib65 in forum AWT / SwingReplies: 4Last Post: 09-25-2010, 04:09 AM -
My own ClassLoader didn't work.
By snooze-g in forum Advanced JavaReplies: 1Last Post: 07-17-2007, 11:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks