标签:需要 test ext code src imp btn lbp getpass
package test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class demo implements ActionListener{
JFrame frame;
JLabel lbuser,lbpsw,lbresult,lbResult;
JTextField tfuser;
JPasswordField pfpsw;
JButton btnLogin,btnReset;
public demo() {
frame=new JFrame("QQ界面");
lbuser=new JLabel("QQ号");
lbpsw=new JLabel("密码");
lbResult=new JLabel();
tfuser=new JTextField();
pfpsw=new JPasswordField();
btnLogin=new JButton("登录");
btnReset=new JButton("取消");
frame.setLayout(null);
lbuser.setBounds(10,10,40,30);
lbpsw.setBounds(10,50,40,30);
tfuser.setBounds(60,10,100,30);
pfpsw.setBounds(60,50,100,30);
btnLogin.setBounds(40,90,60,30);
btnReset.setBounds(120,90,60,30);
lbResult.setBounds(40,130,200,30);
frame.add(lbuser);
frame.add(lbpsw);
frame.add(tfuser);
frame.add(pfpsw);
frame.add(btnLogin);
frame.add(btnReset);
frame.add(lbResult);
btnLogin.addActionListener(this);
btnReset.addActionListener(this);
frame.setSize(400,300);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event) {
if(event.getSource() instanceof JButton) {
JButton btn=(JButton)event.getSource();
if(btn==btnLogin) {
String username=tfuser.getText();
String psw=new String(pfpsw.getPassword());
if(username.equals("lidan")&&psw.equals("5201314")) {
lbResult.setText("登陆成功");
}else {
lbResult.setText("登录失败");
}
}else if(btn==btnReset) {
tfuser.setText("");
pfpsw.setText("");
}
}
}
}
1.JPanel与JTabbedPanel容器的运用
package demo;
import java.awt.*;
import java.io.*;
import javax.swing.*;
public class Demo06 {
public static void main(String[] args) {
JFrame frame =new JFrame("welcome to 小新之门");
JTabbedPane tab=new JTabbedPane(JTabbedPane.TOP);
JPanel pan1=new JPanel();
JPanel pan2=new JPanel();
JPanel pan3=new JPanel();
JButton but=new JButton("按钮1");
JLabel lab1=new JLabel("标签");
JLabel lab2=new JLabel(new ImageIcon("E:"+File.separator+"picture"+File.separator+"1.jpg"));
pan1.add(but);
pan2.add(lab1);
pan3.add(lab2);
String path="E:"+File.separator+"picture"+File.separator+"242.png";
tab.addTab("标签选项",but);
tab.addTab("文字选项", pan2);
tab.addTab("图片选项", pan3);
frame.add(tab);
frame.setSize(230,120);
frame.setLocation(300,200);
//frame.pack();
frame.setVisible(true);
}
}
2.JScrollPane的运行
package demo;
import java.awt.*;
import java.io.*;
import javax.swing.*;
public class Demo05 {
public static void main(String[] args) {
JFrame frame =new JFrame("welcome to 小新之门");
String path="E:"+File.separator+"picture"+File.separator+"11.jpg";
Icon icon=new ImageIcon(path);
JPanel pan=new JPanel();
JLabel lab =new JLabel(icon);
pan.add(lab);
JScrollPane scr1=new JScrollPane(pan,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.add(scr1);
frame.setSize(500,400);
frame.setLocation(300,200);
//frame.pack();
frame.setVisible(true);
}
}
3.JSplitPane容器:就是在显示中分很多分割,可以在分割中每一个区域内设置所需要的内容,完成一个界面出现多个内容并且还是分区域块的。
4.JDesktopPane与JInternalFrame两者是相互相成的,同时一起出现。即JDesktopPane规定一个父窗体的基本形式,JInternalFrame规定各个子窗体,JInternalFrame需要加在JDesktopPane中
标签:需要 test ext code src imp btn lbp getpass
原文地址:https://www.cnblogs.com/chenxinxin/p/11863199.html