Java界面編程實(shí)現(xiàn)界面跳轉(zhuǎn)
本文實(shí)例為大家分享了Java界面編程實(shí)現(xiàn)界面跳轉(zhuǎn)的具體代碼,供大家參考,具體內(nèi)容如下
在事件處理中創(chuàng)建對(duì)象
public void actionPerformed(ActionEvent e)
?? ??? ??? ?{
?? ??? ??? ??? ?QQ1 qq1=new QQ1();//為跳轉(zhuǎn)的界面
?
?? ??? ??? ?}步驟:
在主函數(shù)中創(chuàng)建一個(gè)主窗口的對(duì)象
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);
?? ?}
?
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot @Autowired注解注入規(guī)則介紹
這篇文章主要介紹了SpringBoot @Autowired注解注入規(guī)則介紹,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2021-11-11
代理模式:JAVA靜態(tài)代理和動(dòng)態(tài)代理的實(shí)例和實(shí)現(xiàn)詳解
這篇文章主要給大家介紹了關(guān)于Java靜態(tài)代理和動(dòng)態(tài)代理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-08-08
Spring Boot啟動(dòng)過程(五)之Springboot內(nèi)嵌Tomcat對(duì)象的start教程詳解
這篇文章主要介紹了Spring Boot啟動(dòng)過程(五)之Springboot內(nèi)嵌Tomcat對(duì)象的start的相關(guān)資料,需要的朋友可以參考下2017-04-04
Maven中exec插件執(zhí)行Java程序的實(shí)現(xiàn)
在Maven項(xiàng)目中,可以使用Maven的插件來執(zhí)行Java程序,本文主要介紹了Maven中exec插件執(zhí)行Java程序的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12
Springboot設(shè)置文件上傳大小限制的實(shí)現(xiàn)示例
Spring Boot工程嵌入的tomcat限制了請(qǐng)求的文件大小默認(rèn)為1MB,單次請(qǐng)求的文件的總數(shù)不能大于10Mb,本文主要介紹了Springboot設(shè)置文件上傳大小限制的實(shí)現(xiàn)示例,感興趣的可以了解一下2023-11-11
Java Vector和ArrayList的異同分析及實(shí)例講解
在本篇文章里小編給大家整理的是一篇關(guān)于Java Vector和ArrayList的異同分析及實(shí)例講解內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。2021-01-01
Java代碼實(shí)現(xiàn)四種限流算法詳細(xì)介紹
本文主要介紹了Java代碼實(shí)現(xiàn)四種限流算法詳細(xì)介紹,包含固定窗口限流,滑動(dòng)窗口限流,漏桶限流,令牌桶限流,具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05

