View Single Post
Join Date: Jan 2008
Posts: 3,757
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 491
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: need help with jbutton and new jframe

 
0
  #6
Mar 13th, 2008
Originally Posted by hrlygrl923 View Post
It compliles and runs but does not do anything when i click on the button




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.text.DecimalFormat;
import java.io.*;
import javax.swing.JOptionPane;
import java.lang.*;
import java.math.*;

public class last_try implements ActionListener
{

public static void main(String[] args)
{

JFrame f = new JFrame("What would you like to do");
f.setSize(400, 150);
Container content = f.getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout());


JButton button1 = new JButton("Button 1");
JButton button2 = new JButton("Button 2");
JButton button3 = new JButton("Button 3");

Container contentPane = f.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(button1);
contentPane.add(button2);
contentPane.add(button3);


f.addWindowListener(new ExitListener());
f.setVisible(true);
}

public void popUp()
{
JFrame frame = new JFrame("aName");
frame.setSize(500, 500);
frame.setVisible(true);

}


public void actionPerformed(ActionEvent event)
{

if (event.getSource() == "Button 1")
{
JOptionPane.showMessageDialog(null, "Your entry was not in the proper format.");
}

}
}
See post # 2. You never added the action listeners to the buttons. You may have to rearrange/redesign some code and add those action listeners outside of the main function due to the fact that main is static.
Reply With Quote