Java界面編程實現(xiàn)界面跳轉(zhuǎn)
本文實例為大家分享了Java界面編程實現(xiàn)界面跳轉(zhuǎn)的具體代碼,供大家參考,具體內(nèi)容如下
在事件處理中創(chuàng)建對象
public void actionPerformed(ActionEvent e)
?? ??? ??? ?{
?? ??? ??? ??? ?QQ1 qq1=new QQ1();//為跳轉(zhuǎn)的界面
?
?? ??? ??? ?}步驟:
在主函數(shù)中創(chuàng)建一個主窗口的對象
package 界面編程7;
?
public class QQmain {
?
?? ?public static void main(String[] args) {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?QQ qq = new QQ();
?
?? ?}
?
}編寫QQ類,該類中調(diào)用QQ1類、QQ2類 表達(dá)不正確,反正就是調(diào)用被調(diào)用類的構(gòu)造方法

package 界面編程7;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
?
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
?
public class QQ extends JFrame implements ActionListener{
?? ?public QQ() {
?? ??? ?this.setTitle("主界面");
?? ??? ?this.setBounds(100, 100, 300, 400);
?? ??? ?this.setDefaultCloseOperation(EXIT_ON_CLOSE);
?? ??? ?this.setVisible(true);
?? ??? ?
?? ??? ?
?? ??? ?FlowLayout layout = new FlowLayout();
?? ??? ?this.setLayout(layout);
?? ??? ?
?? ??? ?JButton jb1 = new JButton("彈出框");
?? ??? ?JButton jb2 = new JButton("跳轉(zhuǎn)1");
?? ??? ?JButton jb3 = new JButton("跳轉(zhuǎn)2");
?? ??? ?
?? ??? ?this.add(jb1);
?? ??? ?this.add(jb2);
?? ??? ?this.add(jb3);
?? ??? ?
?? ??? ?jb1.addActionListener(this);
?? ??? ?jb1.addActionListener(new ActionListener()?? ??? ?
?? ??? ?{
?? ??? ??? ?public void actionPerformed(ActionEvent e)
?? ??? ??? ?{
?? ??? ??? ??? ?JOptionPane.showMessageDialog(null, "提示內(nèi)容" ,"標(biāo)題", 2);
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ?});
?? ??? ?
?? ??? ?
?? ??? ?
?? ??? ?jb2.addActionListener(this);
?? ??? ?jb2.addActionListener(new ActionListener()?? ??? ?
?? ??? ?{
?? ??? ??? ?public void actionPerformed(ActionEvent e)
?? ??? ??? ?{
?? ??? ??? ??? ?QQ1 qq1=new QQ1();//為跳轉(zhuǎn)的界面
?
?? ??? ??? ?}
?? ??? ?});
?? ??? ?
?? ??? ?
?? ??? ?jb3.addActionListener(this);
?? ??? ?jb3.addActionListener(new ActionListener()?? ??? ?
?? ??? ?{
?? ??? ??? ?public void actionPerformed(ActionEvent e)
?? ??? ??? ?{
?? ??? ??? ??? ?QQ2 qq2=new QQ2();//為跳轉(zhuǎn)的界面
?
?? ??? ??? ?}
?? ??? ?});
?? ??? ?
?? ?}
?
?? ?@Override
?? ?public void actionPerformed(ActionEvent e) {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?System.out.println("總處理");
?? ?}
?
?
}QQ1類 該類中調(diào)用QQ2類

package 界面編程7;
?
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
?
import javax.swing.JButton;
import javax.swing.JFrame;
?
public class QQ1 extends JFrame implements ActionListener{
?? ?public ?QQ1() {
?? ??? ?this.setTitle("界面1");
?? ??? ?this.setBounds(200, 200, 300, 400);
?? ??? ?this.setDefaultCloseOperation(EXIT_ON_CLOSE);
?? ??? ?this.setVisible(true);
?? ??? ?
?? ??? ?
?? ??? ?FlowLayout layout = new FlowLayout();
?? ??? ?this.setLayout(layout);
?? ??? ?
?? ??? ?JButton jb1 = new JButton("跳轉(zhuǎn)");
?? ??? ?
?? ??? ?
?? ??? ?this.add(jb1);
?? ??? ?jb1.addActionListener(this);
?? ?}
?
?? ?@Override
?? ?public void actionPerformed(ActionEvent e) {
?? ??? ?
?? ??? ?QQ2 qq3 = new QQ2();
?? ??? ?
?? ?}
?
}QQ2類

package 界面編程7;
?
import java.awt.FlowLayout;
?
import javax.swing.JFrame;
import javax.swing.JLabel;
?
public class QQ2 extends JFrame{
?? ?public QQ2() {
?? ??? ?this.setTitle("界面2");
?? ??? ?this.setBounds(200, 200, 300, 400);
?? ??? ?this.setDefaultCloseOperation(EXIT_ON_CLOSE);
?? ??? ?this.setVisible(true);
?? ??? ?
?? ??? ?FlowLayout layout = new FlowLayout();
?? ??? ?this.setLayout(layout);
?? ??? ?
?? ??? ?JLabel jlb = new JLabel("界面2");
?? ??? ?this.add(jlb);
?? ?}
?
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
簡單實現(xiàn)Java版學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了簡單實現(xiàn)Java版學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-06-06
spring cloud gateway請求跨域問題解決方案
這篇文章主要介紹了spring cloud gateway請求跨域問題解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-01-01
mybatis-plus阻止全表更新與刪除的實現(xiàn)
BlockAttackInnerInterceptor 是mybatis-plus的一個內(nèi)置攔截器,用于防止惡意的全表更新或刪除操作,本文主要介紹了mybatis-plus阻止全表更新與刪除的實現(xiàn),感興趣的可以了解一下2023-12-12
Java?循環(huán)隊列/環(huán)形隊列的實現(xiàn)流程
循環(huán)隊列又叫環(huán)形隊列,是一種特殊的隊列。循環(huán)隊列解決了隊列出隊時需要將所有數(shù)據(jù)前移一位的問題。本文將帶大家詳細(xì)了解循環(huán)隊列如何實現(xiàn),需要的朋友可以參考一下2022-02-02
Java實現(xiàn)過濾掉map集合中key或value為空的值示例
這篇文章主要介紹了Java實現(xiàn)過濾掉map集合中key或value為空的值,涉及java針對map的簡單遍歷、判斷、移除等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06

