1

プログラムを実行しようとするたびに、空のウィンドウだけが表示され、その理由がわかりません。メインメソッド内にほとんどすべてがあったときは、以前はウィンドウにすべてを表示することができましたが、今は別のことを試してみると表示されず、閉じてもプログラムの実行が停止しません私のコードでそれを説明したと思いました。コードには他にも問題があるかもしれませんが、本当に助けが必要なのはこれだけです。

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

}

 }
4

2 に答える 2

1

メイン メソッドでは、AirplaneSeats オブジェクトではなく、プレーンなバニラ JFrame オブジェクトを作成して表示するだけです。おそらく、代わりに AirplaneSeats オブジェクトを作成して表示したいと思いませんか?

于 2012-04-22T19:08:14.540 に答える
0

メインメソッドを次のように変更します

public static void main(String [] args){
   AirplaneSeats airplaneSeats = new AirplaneSeats();
   airplaneSeats.setVisible(true);
}

JFrame frame = new JFrame("Island Airlines");のjframeを作成するだけです。

于 2012-04-22T19:22:12.627 に答える