zoukankan      html  css  js  c++  java
  • 第七次上机

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.GridLayout;

    import javax.swing.*;

    public class keytef {
    String[] k=new String[]{"7","8","9","/","4","5","6","*","1","2","3","-","0",".","=","+"};
    JFrame j;
    JPanel P1,p2;
    JTextField t;
    JButton[] b=new JButton[16];
    public keytef(){
    j=new JFrame("计算器");
    t=new JTextField(100);
    p2=new JPanel(new GridLayout(4,4));
    p2.setBackground(Color.red);
    for(int i=0;i<16;i++){
    b[i]=new JButton(k[i]);
    p2.add(b[i]);
    }
    j.add(t,BorderLayout.NORTH);
    j.add(p2);
    j.setSize(300, 200);
    j.setLocation(300,400);
    j.setVisible(true);
    }

    public static void main(String[] args) {
    	new keytef();
    
    }
    

    }

    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;

    public class keysst implements ActionListener{
    JFrame j;
    JButton b1,b2,b3,b4;
    JPanel p;
    public keysst(){
    j=new JFrame();
    p=new JPanel();
    b1=new JButton("红色");
    b1.addActionListener(new bread1());
    b2=new JButton("绿色");
    b2.addActionListener(new bread2());
    b3=new JButton("蓝色");
    b3.addActionListener(new bread3());
    b4=new JButton("灰色");
    b4.addActionListener(this);
    p.setBackground(Color.lightGray);
    p.add(b1);
    p.add(b2);
    p.add(b3);
    p.add(b4);
    j.add(p);
    j.setSize(400, 300);
    j.setLocation(200, 300);
    j.setVisible(true);
    }

    public static void main(String[] args) {
    	new keysst();
    
    }
    
    public class bread1 implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
    	p.setBackground(Color.red);
    	
    }
    }
    
    public class bread2 implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
    	p.setBackground(Color.green);
    	
    }
    }
    
    public class bread3 implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
    	p.setBackground(Color.blue);
    	
    }
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
    	p.setBackground(Color.lightGray);
    	
    }
    

    }

  • 相关阅读:
    ms08-067
    siem主流厂商
    技术设计
    SOC
    通过 IDE 向 Storm 集群远程提交 topology
    Storm
    java线程中Exchanger使用
    android笔记
    学习笔记 Java类的封装、继承和多态 2014.7.10
    POJ 2533 Longest Ordered Subsequence DP
  • 原文地址:https://www.cnblogs.com/javalv/p/10925630.html
Copyright © 2011-2022 走看看