rj
01-16-2013, 04:09 AM
I made a button in java and when I click it it is supposed to show the message in the debug box.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Mypanel extends JPanel {
private JButton Button;
public Mypanel() {
//construct components
Button = new JButton ("DOmath");
//adjust size and set layout
setPreferredSize (new Dimension (944, 585));
setLayout (null);
//add components
add (Button);
//set component bounds (only needed by Absolute Positioning)
Button.setBounds (370, 260, 140, 20);
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new Mypanel());
frame.pack();
frame.setVisible (true);
}
private void jDOmathActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("Hello");
}
}
I also tried:
public class Mypanel extends JPanel {
private JButton Button;
public Mypanel() {
//construct components
Button = new JButton ("DOmath");
//adjust size and set layout
setPreferredSize (new Dimension (944, 585));
setLayout (null);
//add components
add (Button);
//set component bounds (only needed by Absolute Positioning)
Button.setBounds (370, 260, 140, 20);
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new Mypanel());
frame.pack();
frame.setVisible (true);
}
public void actionPerformed(ActionEvent e) {
System.out.println("Hello");
}
}
I have also tried this but I get an error:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Mypanel extends JPanel {
private JButton Button;
public Mypanel() {
//construct components
Button = new JButton ("DOmath");
//adjust size and set layout
setPreferredSize (new Dimension (944, 585));
setLayout (null);
//add components
add (Button);
//set component bounds (only needed by Absolute Positioning)
Button.setBounds (370, 260, 140, 20);
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new Mypanel());
frame.pack();
frame.setVisible (true);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello");
}
});
}
}
"button cannot be resolved' No matter what I change the variable to it sais variable + cannot be resolved
Don't see whats wrong...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Mypanel extends JPanel {
private JButton Button;
public Mypanel() {
//construct components
Button = new JButton ("DOmath");
//adjust size and set layout
setPreferredSize (new Dimension (944, 585));
setLayout (null);
//add components
add (Button);
//set component bounds (only needed by Absolute Positioning)
Button.setBounds (370, 260, 140, 20);
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new Mypanel());
frame.pack();
frame.setVisible (true);
}
private void jDOmathActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("Hello");
}
}
I also tried:
public class Mypanel extends JPanel {
private JButton Button;
public Mypanel() {
//construct components
Button = new JButton ("DOmath");
//adjust size and set layout
setPreferredSize (new Dimension (944, 585));
setLayout (null);
//add components
add (Button);
//set component bounds (only needed by Absolute Positioning)
Button.setBounds (370, 260, 140, 20);
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new Mypanel());
frame.pack();
frame.setVisible (true);
}
public void actionPerformed(ActionEvent e) {
System.out.println("Hello");
}
}
I have also tried this but I get an error:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Mypanel extends JPanel {
private JButton Button;
public Mypanel() {
//construct components
Button = new JButton ("DOmath");
//adjust size and set layout
setPreferredSize (new Dimension (944, 585));
setLayout (null);
//add components
add (Button);
//set component bounds (only needed by Absolute Positioning)
Button.setBounds (370, 260, 140, 20);
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new Mypanel());
frame.pack();
frame.setVisible (true);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello");
}
});
}
}
"button cannot be resolved' No matter what I change the variable to it sais variable + cannot be resolved
Don't see whats wrong...