每次我尝试运行程序时,只出现一个空窗口,我不知道为什么。以前,当我在 main 方法中拥有几乎所有东西时,我能够让所有东西都出现在窗口中,但是现在当我尝试不同的东西时,它就不会出现,即使我关闭它也不会阻止程序运行以为我在我的代码中解释了这一点。代码可能还有其他问题,但我真正需要帮助的唯一一个就是这个。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class AirplaneSeats extends JFrame implements ActionListener{
private static final int FRAME_WIDTH = 400;
private static final int FRAME_HEIGHT = 300;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
private JLabel reservetype = new JLabel("Select Reservation Type:");
private JLabel greenseat = new JLabel("Select availiable (green numbered) seat:");
private JButton firstclass;
private JButton coach;
private JButton one;
private JButton two;
private JButton three;
private JButton four;
private JButton five;
private JButton six;
private JButton seven;
private JButton eight;
private JButton nine;
private JButton ten;
private JButton eleven;
private JButton twelve;
private JButton nothing;
public static void main(String [] args){
JFrame frame = new JFrame("Island Airlines");
frame.setVisible(true);
}
public AirplaneSeats(){
Container contentPane;
contentPane= getContentPane();
contentPane.setLayout(null);
contentPane.setBackground(Color.white);
setTitle("JMenuFrame: Testing Swing Menus");
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setLocation(FRAME_X_ORIGIN,FRAME_Y_ORIGIN);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
reservetype.setBounds(10, 10, 200, 20);
greenseat.setBounds(10, 100, 250, 20);
contentPane.add(reservetype);
contentPane.add(greenseat);
firstclass = new JButton("first class");
coach = new JButton("coach");
contentPane.add(firstclass);
contentPane.add(coach);
firstclass.setBounds(60, 40, 80, 35);
coach.setBounds(150, 40, 80, 35);
firstclass.addActionListener(this);
coach.addActionListener(this);
one = new JButton("1");
two = new JButton("2");
three = new JButton("3");
four = new JButton("4");
five = new JButton("5");
six = new JButton("6");
seven = new JButton("7");
eight = new JButton("8");
nine = new JButton("9");
ten = new JButton("10");
eleven = new JButton("11");
twelve = new JButton("12");
nothing = new JButton("");
one.setBounds(20, 120, 30, 30);
three.setBounds(60, 120, 30, 30);
five.setBounds(100, 120, 30, 30);
seven.setBounds(150, 120, 30, 30);
nine.setBounds(190, 120, 30, 30);
eleven.setBounds(230, 120, 30, 30);
two.setBounds(20, 160, 30, 30);
four.setBounds(60, 160, 30, 30);
six.setBounds(100, 160, 30, 30);
eight.setBounds(150, 160, 30, 30);
ten.setBounds(190, 160, 30, 30);
twelve.setBounds(230, 160, 30, 30);
contentPane.add(one);
contentPane.add(two);
contentPane.add(three);
contentPane.add(four);
contentPane.add(five);
contentPane.add(six);
contentPane.add(seven);
contentPane.add(eight);
contentPane.add(nine);
contentPane.add(ten);
contentPane.add(eleven);
contentPane.add(twelve);
contentPane.add(nothing);
one.addActionListener(this);
two.addActionListener(this);
three.addActionListener(this);
four.addActionListener(this);
five.addActionListener(this);
six.addActionListener(this);
seven.addActionListener(this);
eight.addActionListener(this);
nine.addActionListener(this);
ten.addActionListener(this);
eleven.addActionListener(this);
twelve.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent event) {
// TODO Auto-generated method stub
}
}