实验十一 ,实验十二

实验十一:

源代码:

package ji;

import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

//import 例题62.QueryFrame.WinClose;

public class Add extends Frame{
public static void main(String[]arg){new Add();}

private Button button_char;//button_nui;
public Add() {
super("运算器");
this.setSize(400,200);
this.setLocation(300,240);
this.setBackground(Color.white);
this.setLayout(new FlowLayout());

this.add(new TextField("10",8));
this.add(new Label("+"));
this.add(new TextField("20",8));
this.button_char=new Button("=");
this.add(this.button_char);
this.add(new TextField(10));

this.add(new TextField("30",8));
this.add(new Label("-"));
this.add(new TextField("20",8));
this.button_char=new Button("=");
this.add(this.button_char);
//this.add(new Button("="));
this.add(new TextField(10));

this.add(new TextField("10",8));
this.add(new Label("*"));
this.add(new TextField("20",8));
this.button_char=new Button("=");
this.add(this.button_char);
//this.add(new Button("="));
this.add(new TextField(10));

this.add(new TextField("10",8));
this.add(new Label("/"));
this.add(new TextField("2",8));
this.button_char=new Button("=");
this.add(this.button_char);
//this.add(new Button("="));
this.add(new TextField(10));

button_char.addActionListener(new MyActionListener());

this.setVisible(true);
this.addWindowListener(new WinClose());
}



class MyActionListener implements ActionListener{
// 事件处理方法
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("有人点击了按钮");
System.out.println(((Button)e.getSource()).getLabel());}
}

 

public class WinClose implements WindowListener
{

@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub

}
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
// TODO Auto-generated method stub
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub

}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub

}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub

}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub

}

}}

实验心得:

本次实验相比上一次实验,添加了事件监听,是程序功能更加完善。

 

实验十二:

package 实验十二;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
@SuppressWarnings("unused")
public class Jianli{
 public static void main(String[] args) {
  JFrame jf1=new JFrame("简历");
  jf1.getContentPane().setLayout(new FlowLayout());
  jf1.getContentPane().add(new JLabel("姓名"));
  jf1.getContentPane().add(new JTextField(20));
  jf1.getContentPane().add(new JLabel("性别"));
  JRadioButton j2=new JRadioButton("女");
  jf1.add(j2);
  jf1.getContentPane().add(new JLabel(""));
  JRadioButton j21=new JRadioButton("男");
  jf1.add(j21);
  jf1.getContentPane().add(new JLabel("民族"));
  jf1.getContentPane().add(new JTextField(20));
  jf1.getContentPane().add(new JLabel("年龄"));
  jf1.getContentPane().add(new JTextField(20));
  jf1.getContentPane().add(new JLabel("专业"));
  jf1.getContentPane().add(new JLabel("从以下选择"));
  jf1.getContentPane().add(new JLabel("网络工程"));
  jf1.getContentPane().add(new JRadioButton("是"));
  jf1.getContentPane().add(new JLabel("物联网工程"));
  jf1.getContentPane().add(new JRadioButton("是"));
  jf1.getContentPane().add(new JLabel("软件工程"));
  jf1.getContentPane().add(new JRadioButton("是"));
  jf1.getContentPane().add(new JLabel("计算机科学与技术"));
  jf1.getContentPane().add(new JRadioButton("是"));
  jf1.setLayout(new GridLayout(15,2));
  jf1.setSize(400, 400);
  jf1.setVisible(true);
 }
}

 

实验心得:swing组件比起awt组件更加方便,不需要使用多余的事件监听。

转载于:https://www.cnblogs.com/myb1128/p/11041352.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值