Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

yves032784

[java] simple GUI question

This topic is 5316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, this is a should be fairly simple for anybody who has experience with java, but i can''t seem to figure it out since i''m new to the language. I''m able to display my JFrame, but the buttons just wont be displayed (all the JButtons are not displayed in my JFrame...) here is my code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


public class BushAdvisor extends JFrame implements ActionListener
{
	
	private JComboBox locationCBox;
	private JButton addButton=new JButton("Add");
	private JButton modifyButton=new JButton ("Modify");
	private JButton removeButton=new JButton("Remove");

	public static void main(String[] args)
	{
		
		BushAdvisor test=new BushAdvisor();
		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		test.setSize(500,500);
		test.show();
	}	
	
	public void BushAdvisor()
	{
		Container c=this.getContentPane();
		c.setLayout(new FlowLayout());
		c.add(addButton);
		c.add(modifyButton);
		c.add(removeButton);
	
		addButton.addActionListener(this);
	
	}
	
	public void actionPerformed(ActionEvent event)
	{
		if(event.getSource()==addButton)
		{
			//do something
		}
		
	}
}
 

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The problem is that public void BushAdvisor() {...} is not a constructor, but a method with the same name as the class. Remove the "void" in the definition.
I suggest that you use a Java IDE such as Eclipse that warns you about this kind of problems.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!