JFrame设计面板看起来很空

时间:2012-04-11 08:44:21

标签: java eclipse jframe windowbuilder

我使用JFrame中的设计面板创建了一个窗口,它没有任何问题。但突然间,当我尝试使用设计编辑窗口时,没有任何显示。我甚至无法运行该窗口,但是如果我从上一页开始运行它,它会显示出来(我使用setVisible方法来执行此操作)。您可以在下面看到我的代码:

import java.awt.EventQueue;

public class seat extends JFrame {

    private JPanel contentPane;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    seat frame = new seat();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public seat(String from, String to, String time, String date) {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(380, 230, 50, 300);
        this.setTitle("Flight Reservation System");
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel time1 = DefaultComponentFactory.getInstance().createTitle("- " + time);
        time1.setBackground(SystemColor.windowBorder);
        time1.setForeground(Color.BLACK);
        time1.setFont(new Font("Tahoma", Font.PLAIN, 11));
        time1.setBounds(338, 16, 55, 25);
        contentPane.add(time1);

        JLabel from1 = DefaultComponentFactory.getInstance().createTitle(from.substring(0, 3));
        from1.setFont(new Font("Tahoma", Font.PLAIN, 11));
        from1.setBounds(65, 16, 38, 25);
        contentPane.add(from1);

        JLabel to1 = DefaultComponentFactory.getInstance().createTitle("- " + to.substring(0, 3));
        to1.setFont(new Font("Tahoma", Font.PLAIN, 11));
        to1.setBounds(84, 16, 55, 25);
        contentPane.add(to1);

        date = date.replace(".", "/");
        JLabel date1 = DefaultComponentFactory.getInstance().createTitle(date.substring(0, 11));
        date1.setFont(new Font("Tahoma", Font.PLAIN, 11));
        date1.setBounds(277, 16, 67, 25);
        contentPane.add(date1);

        JLabel label_14 = new JLabel("");
        label_14.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\asdasd.png"));
        label_14.setBounds(60, 47, 19, 108);
        contentPane.add(label_14);

        JLabel a1 = new JLabel(" ");
        a1.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        a1.setBounds(71, 58, 39, 43);
        contentPane.add(a1);

        JLabel koltuk1 = new JLabel(" ");
        koltuk1.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        koltuk1.setBounds(109, 58, 38, 43);
        contentPane.add(koltuk1);

        JLabel koltuk2 = new JLabel(" ");
        koltuk2.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        koltuk2.setBounds(147, 58, 38, 43);
        contentPane.add(koltuk2);

        JLabel label_1 = new JLabel(" ");
        label_1.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_1.setBounds(185, 58, 38, 43);
        contentPane.add(label_1);

        JLabel label_2 = new JLabel(" ");
        label_2.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_2.setBounds(223, 58, 38, 43);
        contentPane.add(label_2);

        JLabel label_3 = new JLabel(" ");
        label_3.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_3.setBounds(261, 58, 38, 43);
        contentPane.add(label_3);

        JLabel label_4 = new JLabel(" ");
        label_4.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_4.setBounds(299, 58, 38, 43);
        contentPane.add(label_4);

        JLabel label_5 = new JLabel(" ");
        label_5.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_5.setBounds(337, 58, 38, 43);
        contentPane.add(label_5);

        JLabel lblNewLabel_2 = new JLabel(" ");
        lblNewLabel_2.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\cccccccccc.png"));
        lblNewLabel_2.setBounds(71, 97, 304, 20);
        contentPane.add(lblNewLabel_2);

        JLabel label_6 = new JLabel(" ");
        label_6.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_6.setBounds(71, 112, 38, 43);
        contentPane.add(label_6);

        JLabel label_7 = new JLabel(" ");
        label_7.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_7.setBounds(109, 112, 38, 43);
        contentPane.add(label_7);

        JLabel label_8 = new JLabel(" ");
        label_8.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_8.setBounds(147, 112, 38, 43);
        contentPane.add(label_8);

        JLabel label_9 = new JLabel(" ");
        label_9.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_9.setBounds(185, 112, 38, 43);
        contentPane.add(label_9);

        JLabel label_10 = new JLabel(" ");
        label_10.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_10.setBounds(223, 112, 38, 43);
        contentPane.add(label_10);

        JLabel label_11 = new JLabel(" ");
        label_11.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_11.setBounds(261, 112, 38, 43);
        contentPane.add(label_11);

        JLabel label_12 = new JLabel(" ");
        label_12.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_12.setBounds(299, 112, 38, 43);
        contentPane.add(label_12);

        JLabel label_13 = new JLabel(" ");
        label_13.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\Untitled.png"));
        label_13.setBounds(337, 112, 38, 43);
        contentPane.add(label_13);

        JLabel lblNewLabel_3 = new JLabel("");
        lblNewLabel_3.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\adsd.png"));
        lblNewLabel_3.setBounds(63, 40, 312, 26);
        contentPane.add(lblNewLabel_3);

        JLabel lblNewLabel_4 = new JLabel("");
        lblNewLabel_4.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\seats\\empty.png"));
        lblNewLabel_4.setBounds(81, 163, 46, 43);
        contentPane.add(lblNewLabel_4);

        JLabel label_15 = new JLabel("");
        label_15.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\seats\\selected.png"));
        label_15.setBounds(164, 166, 46, 43);
        contentPane.add(label_15);

        JLabel lblNewLabel_5 = new JLabel("");
        lblNewLabel_5.setIcon(new ImageIcon("C:\\Users\\Emre\\Desktop\\seats\\booked.png"));
        lblNewLabel_5.setBounds(254, 163, 46, 43);
        contentPane.add(lblNewLabel_5);

        JLabel lblSelected = new JLabel("Selected");
        lblSelected.setBounds(202, 176, 57, 14);
        contentPane.add(lblSelected);

        JLabel lblBooked = new JLabel("Booked");
        lblBooked.setBounds(292, 176, 46, 14);
        contentPane.add(lblBooked);

        JLabel lblEmpty = new JLabel("Empty");
        lblEmpty.setBounds(118, 176, 46, 14);
        contentPane.add(lblEmpty);

        JButton btnContinue = new JButton("Next");
        btnContinue.setBounds(359, 227, 62, 23);
        contentPane.add(btnContinue);

        btnContinue.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent arg0) {
                data page = new data();
                page.setVisible(true);
                setVisible(false);
            }
        });
    }

    public seat() {
        // TODO Auto-generated constructor stub
    }

}

2 个答案:

答案 0 :(得分:2)

在public static void main中,只调用空构造函数。您必须使用包含构建GUI的代码的参数调用构造函数。

答案 1 :(得分:1)

而不是使用

调用标准构造函数
seat frame = new seat();

你必须用

来调用它
seat frame = new seat("from", "to", "time", "date");