[英]Java second Frame not showing
我做了一個項目,在表格中您會看到4個按鈕,當您單擊它時,必須出現另一個框,但是當我這樣做時,第二個窗口打開,兩個窗口都關閉,我無法訪問應該從ActionPerformed()中出來,它只是彈出另一個窗口並在不到3秒的時間內關閉而不打開它,其他代碼工作正常,我很累,這是第一個框的代碼:
public class MathoQuest extends JFrame implements ActionListener {
JButton boutConvert, boutGeo, boutFonc, boutOut;
public MathoQuest() {
setTitle("Bienvenue a MathoQuest");
setSize(250,500);
JPanel simplePanel = new JPanel();
simplePanel.setLayout(null);
add(simplePanel);
Font helvb14 = new Font("Arial" , Font.BOLD , 30);
boutConvert = new JButton("Convertir");
boutConvert.setFont(helvb14);
boutConvert.setForeground(Color.white);
boutConvert.setBackground(new Color(63,107,220));
simplePanel.add(boutConvert);
boutConvert.setBounds(25,50,200,80);
boutConvert.addActionListener(this);
boutGeo = new JButton("Geometrie-\nEN CONSTRUCTION-");
boutGeo.setFont(helvb14);
boutConvert.setForeground(Color.white);
boutGeo.setBackground(new Color(145,110,220));
simplePanel.add(boutGeo);
boutGeo.setBounds(25,150,200,80);
boutGeo.addActionListener(this);
boutFonc = new JButton("Fonction");
boutFonc.setFont(helvb14);
boutFonc.setForeground(Color.white);
boutFonc.setBackground(new Color(150,200,80));
simplePanel.add(boutFonc);
boutFonc.setBounds(25,250,200,80);
boutFonc.addActionListener(this);
boutOut = new JButton("Quitter");
boutOut.setFont(helvb14);
boutOut.setForeground(Color.white);
boutOut.setBackground(new Color(245,130,0));
simplePanel.add(boutOut);
boutOut.setBounds(25,350,200,80);
boutOut.addActionListener(this);
}
public static void main(String[] args) {
MathoQuest mathframe = new MathoQuest();
mathframe.setVisible(true);
mathframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == boutConvert) {
ConversionFrame frame = new ConversionFrame();
frame.getContentPane();
frame.setVisible(true);
}
if (e.getSource() == boutGeo) {
JOptionPane.showMessageDialog(null,"Ce mode est encore en construction merci de reessayer plus tard");
}
if (e.getSource() == boutFonc) {
FonctionFrame dess = new FonctionFrame();
dess.getContentPane();
dess.setVisible(true);
}
if (e.getSource() == boutOut)
JOptionPane.showMessageDialog(null,"Au revoir et merci d'avoir utilise cette application");
System.exit(0);
}
}
您是否嘗試將最后一個if
條件括在括號中?
不包含它們, System.exit(0);
在任何情況下都將被調用,並且if
之后的立即行將成為其中的一部分。
因此,退出方法將是直接方法的一部分,而不是if
塊的一部分。
實際上,該程序將如下所示:
if (e.getSource() == boutOut)
{
JOptionPane.showMessageDialog(null,"Au revoir et merci d'avoir utilise cette application");
}
System.exit(0);
看起來應該像這樣:
if (e.getSource() == boutOut)
{
JOptionPane.showMessageDialog(null,"Au revoir et merci d'avoir utilise cette application");
System.exit(0);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.