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
}
}
}
[java] simple GUI question
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:
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.
I suggest that you use a Java IDE such as Eclipse that warns you about this kind of problems.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement