my main:
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TicketMan {
public static void main(String[] args) {
JFrame frame = new JFrame ("Airport");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
TicketManBot panel = new TicketManBot();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
the class that it extends from
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class TicketManBot extends JPanel {
private JLabel name;
private JLabel dest;
private JLabel depc;
private JLabel dept;
private JLabel seat;
private JButton b;
Random rand = new Random();
private JTextField namef, destf, depcf, deptf;
public TicketManBot()
{
name = new JLabel ("Enter passenger's name:");
dest = new JLabel ("Destination: ");
depc = new JLabel ("Departure city: ");
dept = new JLabel ("Departure time: ");
seat = new JLabel ("Seat Number: " + rand.nextInt(100));
b = new JButton ("Make Reservation");
b.addActionListener (new Action());
namef = new JTextField (10);
destf = new JTextField (10);
depcf = new JTextField (10);
deptf = new JTextField (10);
}{
add (name);
add (namef);
add (dest);
add (destf);
add (depc);
add (depcf);
add (dept);
add (deptf);
add (seat);
add (b);
setPreferredSize (new Dimension(200, 300));
setBackground (Color.gray);
}
private class TempListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
int resultLabel;
String text = namef.getText();
}}
static class Action implements ActionListener {
public void actionPerformed (ActionEvent e){
JFrame results = new JFrame("clicked");
results.setVisible(true);
results.setSize(200, 200);
JLabel label = new JLabel ("you clicked me");
JPanel panel = new JPanel ();
results.add(panel);
panel.add (label);
}
}
}
I'm trying to make the button open a new frame but it gives me errors. HELP....please