zoukankan      html  css  js  c++  java
  • 窗口实训1

    package xzx;
    import java.awt.*;
    import javax.swing.*;
    public class 计算器{
    JFrame jf ;
    JPanel jp1,jp2;
    JTextField t1;
    JButton j1,j2,j3,j4,j5,j6,j7,j8,j9,j10,j11,j12,j13,j14;
    public static void main(String[] args) {
    JFrame jf =new JFrame("计算器");
    jf.setSize(500,400); //设置窗体大小
    jf.setBackground(Color.PINK); //设置背景颜色
    jf.setLocation(300,200); //设置窗体显示位置
    jf.setVisible(true); //显示窗体
    JPanel jp1=new JPanel();
    JPanel jp2=new JPanel();
    JButton j1=new JButton("1");
    JButton j2=new JButton("2");
    JButton j3=new JButton("3");
    JButton j4=new JButton("4");
    JButton j5=new JButton("5");
    JButton j6=new JButton("6");
    JButton j7=new JButton("7");
    JButton j8=new JButton("8");
    JButton j9=new JButton("9");
    JButton j10=new JButton("/");
    JButton j11=new JButton("*");
    JButton j12=new JButton("-");
    JButton j13=new JButton("+");
    JButton j14=new JButton("=");
    JButton j15=new JButton(".");
    JButton j16=new JButton("0");
    jp2.setLayout(new GridLayout(4,4));
    jp1.setLayout(new BorderLayout());
    jp1.add("North", new JTextField(42));
    jf.add(jp1);
    jp1.add(jp2);
    jp2.add(j7);
    jp2.add(j8);
    jp2.add(j9);
    jp2.add(j10);
    jp2.add(j4);
    jp2.add(j5);
    jp2.add(j6);
    jp2.add(j11);
    jp2.add(j1);
    jp2.add(j2);
    jp2.add(j3);
    jp2.add(j12);
    jp2.add(j16);
    jp2.add(j15);
    jp2.add(j14);
    jp2.add(j13);

    }

    }

    package xzx;


    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    public class 颜色窗口 implements ActionListener{
    JFrame f;
    JPanel p1,p2;
    BorderLayout bl;
    GridLayout gl;
    JButton b1,b2,b3;
    public 颜色窗口(){
    f=new JFrame("颜色");
    p1=new JPanel();
    p2=new JPanel();
    b1=new JButton("红色");
    b2=new JButton("绿色");
    b3=new JButton("蓝色");
    f.setBounds(760, 440, 400, 400);
    f.add(p1,BorderLayout.NORTH);
    f.add(p2,BorderLayout.CENTER);
    p1.add(b1);
    p1.add(b2);
    p1.add(b3);
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    f.setVisible(true);
    }
    public static void main(String[] args) {
    new 颜色窗口();
    }
    public void actionPerformed(ActionEvent e){
    if(e.getSource()==b1)
    p2.setBackground(Color.red);
    else if(e.getSource()==b2)
    p2.setBackground(Color.green);
    else if(e.getSource()==b3)
    p2.setBackground(Color.blue);
    }

    }

  • 相关阅读:
    【tarjan】BZOJ 1051:受欢迎的牛
    【递推】BZOJ 1088: [SCOI2005]扫雷Mine
    【计算几何】多边形
    【贪心】Bzoj 2457:[BeiJing2011]双端队列
    【单调栈】Bzoj 1012: 最大数maxnumber
    [洛谷P3584] POI2015 LAS
    [洛谷P4049] JSOI2007 合金
    [51nod1533] 一堆的堆
    [AGC018E] Sightseeing Plan
    [CF1065E] Side Transmutations
  • 原文地址:https://www.cnblogs.com/xiezhixin/p/10926552.html
Copyright © 2011-2022 走看看