zoukankan      html  css  js  c++  java
  • 第十二周总结

    话不多说,先上代码

    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中

    说的太多,还如在代码中用用。。。。。

    图片都用完了,将就点哦!!


    When in the bottom of mountain,you should hang on;

    when in the top of mountain ,you should be pride of yourself.Don't be always.

  • 相关阅读:
    golang动态加载原生代码思路
    boltdb的实现和改进
    如何保证数据掉电不损坏?
    msgpack库的神奇用法
    消息推送与同步协议的思考
    cassandra的gc调优
    tcp链接断开的探测
    加速和监控国际网络
    轻松逃脱某防火墙对ss的探测
    java文件操作之war压缩解压
  • 原文地址:https://www.cnblogs.com/chenxinxin/p/11863199.html
Copyright © 2011-2022 走看看