导航:首页 > 编程语言 > java2图形设计

java2图形设计

发布时间:2024-12-05 02:32:31

java图形界面设计如何从一个界面跳到另外界面再返回

import java.awt.BorderLayout;x0dx0aimport java.awt.Color;x0dx0aimport java.awt.FlowLayout;x0dx0aimport java.awt.Font;x0dx0aimport java.awt.event.ActionEvent;x0dx0aimport java.awt.event.ActionListener;x0dx0aimport java.awt.event.KeyEvent;x0dx0aimport java.awt.event.KeyListener;x0dx0aimport java.util.Calendar;x0dx0ax0dx0aimport javax.swing.JButton;x0dx0aimport javax.swing.JFrame;x0dx0aimport javax.swing.JLabel;x0dx0aimport javax.swing.JOptionPane;x0dx0aimport javax.swing.JPasswordField;x0dx0aimport javax.swing.JTextArea;x0dx0ax0dx0apublic class Test2{x0dx0apublic Test2() {}x0dx0ax0dx0aJFrame frame; //主界面框架x0dx0ax0dx0a//主界面函数x0dx0apublic void mainFace() {x0dx0aframe=new JFrame("主界面");x0dx0aframe.setLayout(new BorderLayout());x0dx0ax0dx0aJLabel label=new JLabel("这是主界面");x0dx0aframe.add(label,BorderLayout.CENTER);x0dx0ax0dx0aJButton button=new JButton("进入另一个界面");x0dx0aframe.add(button,BorderLayout.SOUTH);x0dx0abutton.addActionListener(new ActionListener() {x0dx0ax0dx0a@Overridex0dx0apublic void actionPerformed(ActionEvent e) {x0dx0aotherFace(); //进入另一个界面x0dx0aframe.dispose(); //主界面关闭x0dx0a}x0dx0ax0dx0a});x0dx0ax0dx0aframe.setSize(400,300);x0dx0aframe.setLocation(100,50);x0dx0aframe.setVisible(true);x0dx0aframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);x0dx0a}x0dx0ax0dx0a//另一个图形界面x0dx0apublic void otherFace() {x0dx0afinal JFrame oframe=new JFrame("另一个界面");x0dx0aoframe.setLayout(new BorderLayout());x0dx0ax0dx0aJTextArea displayArea=new JTextArea();x0dx0aoframe.add(displayArea,BorderLayout.CENTER);x0dx0adisplayArea.setFont(new Font("宋体",Font.BOLD,30));x0dx0adisplayArea.setForeground(Color.red);x0dx0ax0dx0adisplayArea.append("\n\n\n\n 这是另一个图形界面");x0dx0ax0dx0aJButton button1=new JButton("返回主界面");x0dx0aoframe.add(button1,BorderLayout.SOUTH);x0dx0ax0dx0abutton1.addActionListener(new ActionListener() {x0dx0ax0dx0a@Overridex0dx0apublic void actionPerformed(ActionEvent e) {x0dx0aframe.setVisible(true); //主界面显示x0dx0aoframe.dispose(); //另一个界面关闭x0dx0a}x0dx0ax0dx0a});x0dx0ax0dx0aoframe.setSize(400,300);x0dx0aoframe.setLocation(150,100);x0dx0aoframe.setVisible(true);x0dx0a}x0dx0ax0dx0a//密码输入函数x0dx0apublic void passwordFrame() {x0dx0afinal JFrame keyFrame=new JFrame("Password Input");x0dx0akeyFrame.setLayout(new FlowLayout());x0dx0ax0dx0afinal JPasswordField keyField=new JPasswordField();x0dx0akeyField.setColumns(30);x0dx0akeyField.setFont(new Font("宋体",Font.BOLD,20));x0dx0akeyField.setEchoChar('@');x0dx0akeyFrame.add(keyField);x0dx0a x0dx0aCalendar calendar=Calendar.getInstance();x0dx0ax0dx0aint mon=calendar.get(Calendar.MONTH)+1;x0dx0aint day=calendar.get(Calendar.DAY_OF_MONTH);x0dx0aint h=calendar.get(Calendar.HOUR_OF_DAY);x0dx0aint m=calendar.get(Calendar.MINUTE);x0dx0ax0dx0afinal String nowKey=mon+"."+day+"."+h+"."+m; //密码为现在时间的 月.日.时.分x0dx0ax0dx0akeyField.addKeyListener(new KeyListener() { //给密码框添加键盘监听器x0dx0ax0dx0apublic void keyPressed(KeyEvent e) {x0dx0aif(e.getKeyCode()==KeyEvent.VK_ENTER) {x0dx0achar[] key=keyField.getPassword();x0dx0aString keyStr = String.valueOf(key);x0dx0ax0dx0aif(keyStr.equals(nowKey)) {x0dx0amainFace(); //进入主界面x0dx0akeyFrame.dispose();x0dx0a}x0dx0aelse {x0dx0aJOptionPane.showMessageDialog(null, "输入的密码不正确!");x0dx0a}x0dx0a}x0dx0a}x0dx0ax0dx0a@Overridex0dx0apublic void keyReleased(KeyEvent e) {}x0dx0ax0dx0apublic void keyTyped(KeyEvent e) {}x0dx0ax0dx0a});x0dx0ax0dx0aJButton sureButton=new JButton("确认");x0dx0akeyFrame.add(sureButton);x0dx0asureButton.addActionListener(new ActionListener() { //给'确定'按钮添加动作监听器x0dx0ax0dx0apublic void actionPerformed(ActionEvent e) {x0dx0achar[] key=keyField.getPassword();x0dx0aString keyStr = String.valueOf(key);x0dx0ax0dx0aif(keyStr.equals(nowKey)) {x0dx0amainFace(); //进入主界面x0dx0akeyFrame.dispose();x0dx0a}x0dx0aelse {x0dx0aJOptionPane.showMessageDialog(null, "输入的密码不正确!");x0dx0a}x0dx0a}x0dx0ax0dx0a});x0dx0ax0dx0aJButton cancelButton=new JButton("取消");x0dx0akeyFrame.add(cancelButton);x0dx0acancelButton.addActionListener(new ActionListener() {x0dx0ax0dx0apublic void actionPerformed(ActionEvent e) {x0dx0aSystem.exit(0);x0dx0a}x0dx0ax0dx0a});x0dx0ax0dx0akeyFrame.setSize(400,120);x0dx0akeyFrame.setLocation(300,300);x0dx0akeyFrame.setVisible(true);x0dx0akeyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);x0dx0a}x0dx0ax0dx0a//程序主函数x0dx0apublic static void main(String args[]) {x0dx0aTest2 t2=new Test2();x0dx0at2.passwordFrame();x0dx0a}x0dx0a}

阅读全文

与java2图形设计相关的资料

热点内容
linuxtelnet退出命令 浏览:244
税务局预交2算法 浏览:531
前馈pid算法 浏览:145
安卓怎么使用投影仪 浏览:938
云计算服务器贵州云主机 浏览:389
淘米APP是哪个公司 浏览:452
程序员玩车 浏览:474
安卓腾讯手游换成苹果手机怎么办 浏览:526
主播皮克桃玩的什么安卓区 浏览:565
linux单词统计 浏览:907
小朋友参加密室大逃脱 浏览:218
程序员的三大忌 浏览:284
空调压缩机机头 浏览:765
户户通加密卡号几位 浏览:282
alphabeta剪枝算法 浏览:627
csgo命令台怎么打开 浏览:223
sqldump命令 浏览:718
如何组建服务器运行excel 浏览:131
编译图形用什么语言 浏览:522
基于编译的求解器 浏览:15