zoukankan      html  css  js  c++  java
  • java巅峰作业

    //3
    interface Animal{
    	abstract void run();
    }
    
    class Bird implements Animal{
    	public void run() {
    		System.out.println("Bird测试成功");
    	}
    }
    
    class Fish implements Animal{
    	public void run() {
    		System.out.println("Fish测试成功");
    	}
    }
    
    public class Animaljiekou{
    	public static void main(String[]args) {
    		Animal p1 = new Bird();
    		p1.run();
    		
    		p1 = new Fish();
    		p1.run();
    	}
    }
    
    //1
    
    import java.util.*;
    public class Manager {
    	private int pre;
    	private int cur;
    	public Manager()
    	{
    		this.pre = 0;
    		this.cur = 0;
    		System.out.println("上月="+pre+"   本月="+cur);
    		
    	}
    	public Manager(int pre,int cur)
    	{
    		this.pre = pre;
    		this.cur = cur;
    		System.out.println("上月="+pre+"   本月="+cur);
    	}
    	public int Summation() {
    		int sum;
    		sum =  pre + cur;
    		System.out.println("总共"+sum);
    		return sum;
    	}
    
    }
    
    
    
    public class TestManager {
    
    	public static void main(String[] args) {
    		Manager m1 = new Manager();
    		Manager m2 = new Manager(15,5);
    		m1.Summation();
    		m2.Summation();
    
    
    	}
    
    }
    
    
    //2
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    
    public class UserLogin extends JFrame {
    	JFrame jf;
    	JPanel jpanel;
    	JLabel jl1;
    	JLabel jl2;
    	JLabel jl3;
    	JTextField jt;
    	JPasswordField jp;
    	JButton jb1;
    	JButton jb2;	
    	public void JDialog() {
    		jf =new JFrame();
    		jl3 = new JLabel("暂无数据");
    		jf.setSize(300, 150);
    		jf.add(jp);
    		jp.add(jl3);
    	}			
    	public void CreateJFrame(String title) {
    		jf = new JFrame(title);
    		jpanel = new JPanel();
    		jl1 = new JLabel("用户名");  //标签1
    		jl2 = new JLabel("密   码");   //标签2
    		jt = new JTextField(18);   //文本框1
    		jp = new JPasswordField(18);  //文本框2
    		jb1 = new JButton("登录");   //按钮1
    		jb2 = new JButton("重置");   //按钮2
    		
    		jf.add(jpanel);
    		jpanel.add(jl1);    //添加到容器
    		jpanel.add(jt);
    		jpanel.add(jl2);
    		jpanel.add(jp);
    		jpanel.add(jb1);
    		jb1.addActionListener(new ActionListener() {//给登录按钮添加事件处理
    			public void actionPerformed(ActionEvent e) {
    				JOptionPane.showMessageDialog(null,"暂无数据");
    			}
    		});
    		
    		jpanel.add(jb2);
    		jb2.addActionListener(new ActionListener() {//给重置按钮添加事件处理
    			public void actionPerformed(ActionEvent e) {
    				jt.setText("");
    				jp.setText("");
    			}
    		});
    		
    		jf.setVisible(true);//设置窗口可见
    		jf.setSize(300,150);//设置窗口大小		
    	}
    	public static void main(String[] args) {
    		new UserLogin().CreateJFrame("用户登录");
    	}
    }
    
    

    计算器面板

    
    
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    
    public class Calculator extends JFrame {
    					
    	public void CreateJFrame(String title) {
    		JFrame jf;
    	    JPanel jp1 = new JPanel(new GridLayout(5,3,0,0));//新建一个5*3网格布局的面板
    	    JPanel jp2 = new JPanel(new GridLayout(4,1,0,0));//新建一个4*1网格布局的面板
    	    JTextField jt;                                   //声明文本框
    	    String[] button1 = {"1","2","3","4","5","6","7","8","9","0","清空","退格",".","="};
    	    String[] button2 = {"+","-","*","/"};
    	 
    		jf = new JFrame("计算器");//新建窗口
    		
    		
    		Container c = getContentPane();                //定义一个容器
    		setLayout(new BorderLayout());                 //设定为边界布局
    		jf.add(c);
    		c.add(BorderLayout.NORTH,jt = new JTextField(18));//添加文本框
    		c.add(BorderLayout.CENTER,jp1);                   //在容器的中间加上面板1
    		c.add(BorderLayout.EAST,jp2);                     //在容器的右边加上面板2
    
    
    		for(int i = 0;i<button1.length;i++) {              //给面板1循环添加按钮
    			jp1.add(new JButton(button1[i]));
    		}
    		
    		for(int i = 0;i<button2.length;i++) {             //给面板2循环添加按钮
    			jp2.add(new JButton(button2[i]));
    		}
    
    		jf.setVisible(true);//设置窗口可见
    		jf.setSize(300,300);//设置窗口大小		
    	}
    	public static void main(String[] args) {
    		new Calculator().CreateJFrame("计算器");
    	}
    }
    
  • 相关阅读:
    树莓派基于scratch2控制GPIO
    一次修复linux的efi引导的集中方法总结记录
    linux(deepin) 下隐藏firefox标题栏
    log4j 1.2 配置和使用简述
    在非gnome系桌面环境下运行deepin-wine tim的错误解决
    manjaro AwesomeWM 上使用双显示器
    linux 关闭主板上的蜂鸣器声音
    anki的使用以及anki server的配置
    阅读《人类简史》-- 1.认知革命
    java生成zip包兼容Linux
  • 原文地址:https://www.cnblogs.com/BKKITO/p/11487275.html
Copyright © 2011-2022 走看看