第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

java GUI Form open other form onclick button

java GUI Form open other form onclick button

元芳怎么了 2022-05-21 16:38:47
當(dāng)從form1打開(kāi)form2單擊按鈕時(shí),我正在嘗試做。它聽(tīng)起來(lái)很簡(jiǎn)單,但我找不到任何方法來(lái)做到這一點(diǎn)。我正在使用 java intellij。當(dāng)我使用netbeans和swing時(shí),我正在這樣做:“Form2 form2=new Form2();form2.setVisible(true);處置();"表格1(主要):public class Main {    private JButton b_show;    private JButton b_Add;    private JPanel jp_main;    public Main() {        b_show.addActionListener(new ActionListener() {            @Override            public void actionPerformed(ActionEvent actionEvent) {            }        });    }    public static void main(String[]args){        JFrame frame=new JFrame();        frame.setContentPane(new Main().jp_main);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setSize(300,300);        frame.setVisible(true);    }}表格2(顯示):public class Show {    private JButton b_back;    public JPanel jpanelmain;    public Show() {        Show show=new Show();        geriButton.addActionListener(new ActionListener() {            @Override            public void actionPerformed(ActionEvent actionEvent) {            }        });    }    public static void main(String[]args){        JFrame frame=new JFrame();        frame.setContentPane(new Show().jpanelmain);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setSize(300,300);        frame.setVisible(true);    }}有人可以幫助我嗎?單擊 b_show 時(shí)打開(kāi) form2(顯示)。
查看完整描述

2 回答

?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊

這是一個(gè)演示它的mcve


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;


public class Main {


    private final JButton b_show;

    private final JPanel jp_main;


    public Main() {

        jp_main = new JPanel();

        b_show = new JButton("Show");

        b_show.addActionListener(actionEvent -> {

            new Show();

        });

        jp_main.add(b_show);

    }

    public static void main(String[]args){

        JFrame frame=new JFrame();

        frame.setContentPane(new Main().jp_main);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setSize(300,300);

        frame.setVisible(true);

    }

}


class Show {

    private JButton b_back;

    public JPanel jpanelmain;



    public Show() {

        createAndShowGui();

    }


    void createAndShowGui(){


        JFrame frame=new JFrame();

        frame.setLocationRelativeTo(null);

        jpanelmain = new JPanel();

        b_back = new JButton("Back");

        jpanelmain.add(b_back);

        frame.setContentPane(jpanelmain);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setSize(300,300);

        frame.setVisible(true);

    }


查看完整回答
反對(duì) 回復(fù) 2022-05-21
?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

最好的方法是使用 JDialogs。在actionPerformed()調(diào)用“Form1”時(shí),您將實(shí)例化一個(gè)新的 JDialog 并將其設(shè)置為可見(jiàn)。這是一個(gè)例子:


public class Show extends JDialog {


    private JButton b_back;

    public JPanel jpanelmain;


    public Show(Frame owner, boolean modal) {

        super(owner, modal);

    }


    //method that creates the GUI   

}




b_show.addActionListener(new ActionListener() {

    @Override

    public void actionPerformed(ActionEvent actionEvent) {

        Show show = new Show(JOptionPane.getFrameForComponent(this), true);

        show.setVisible(true);

    }

});

最后,當(dāng)你想關(guān)閉對(duì)話框時(shí),actionPerformed()在里面實(shí)現(xiàn)一個(gè),并調(diào)用dispose()方法


查看完整回答
反對(duì) 回復(fù) 2022-05-21
  • 2 回答
  • 0 關(guān)注
  • 131 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)