生活随笔
收集整理的這篇文章主要介紹了
课后练习----实现窗口的切换
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、運(yùn)用事件處理相關(guān)知識(shí),完成兩個(gè)窗口之間的切換,例如:登陸窗口------》注冊(cè)窗口
2、對(duì)本次作業(yè)進(jìn)行總結(jié),在編程過(guò)程中遇到哪些問(wèn)題,如何解決,有哪些收獲?
源代碼:
package bbb;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class myframe implements ActionListener {JFrame f1,f2;JPanel p1,p2;JButton b1,b2;JLabel l1,l2,l3;JTextField t1,t2;//文本框public myframe() {f1=new JFrame("LYX");f2=new JFrame("LYX");p1=new JPanel();p2=new JPanel();p1.setLayout(null);//絕對(duì)布局p2.setLayout(null);b1=new JButton("注冊(cè)");b2=new JButton("登錄");l1=new JLabel("賬戶"); l1.setFont(new Font("楷體",Font.BOLD,18));//自定義標(biāo)簽字體l2=new JLabel("密碼");l2.setFont(new Font("楷體",Font.BOLD,18));l3=new JLabel("登錄成功!");l3.setForeground(Color.red);t1=new JTextField();t2=new JTextField();b1.addActionListener(this);b2.addActionListener(this);f1.add(p1);p1.add(b1);p1.add(b2);p1.add(l1);p1.add(l2);p1.add(t1);p1.add(t2);b1.setBounds(150,150,60,40);b2.setBounds(270,150,60,40);l1.setBounds(80,50,40,30);l2.setBounds(80,100,40,30);t1.setBounds(120,50,300,30);t2.setBounds(120,100,300,30);f1.setVisible(true);f1.setSize(500,300);}public static void main(String[] args) {new myframe();
}public void actionPerformed(ActionEvent e) {f1.setVisible(false);p2.setBackground(new Color(211,252,4));//自定義面板顏色f2.setVisible(true); f2.add(p2);p2.add(l3);l3.setBounds(225,75,150,60);f2.setLocation(600,0);f2.setSize(500,300);}
}
運(yùn)行結(jié)果:
心得體會(huì):
窗口的學(xué)習(xí)是循序漸進(jìn)的,每次都覺得特別新穎、好玩、有成就感,這次編程中為了美觀,設(shè)計(jì)組件、窗口具體的位置是個(gè)麻煩的地方,還有程序的部分地方都是相似的,所以我選擇了復(fù)制粘貼,但忘記改組件名稱了,花了很長(zhǎng)時(shí)間才發(fā)現(xiàn)問(wèn)題。編程過(guò)程中也總會(huì)遺留一些細(xì)節(jié),希望今后真正地學(xué)懂每個(gè)知識(shí)點(diǎn),而不是死記硬背@-@
轉(zhuǎn)載于:https://www.cnblogs.com/leiyaxi/p/10859277.html
總結(jié)
以上是生活随笔為你收集整理的课后练习----实现窗口的切换的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。