Java中利用图形用户界面和多线程,实现各自“学号 姓名”,从上到下的文字移动?
2个回答
展开全部
import java.awt.Button;import java.awt.FlowLayout;import java.awt.Label;import java.awt.TextArea;import java.awt.TextField;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.TextEvent; import javax.swing.JFrame; /* * java编程 完成下图所示的图形用户界面设计, */public class Demo3 { public static void main(String[] args) { //创建窗体对象 JFrame jf = new JFrame("信息获取"); //设置大小 jf.setSize(300, 300); //设置居中 jf.setLocationRelativeTo(null); //设置布局 jf.setLayout(new FlowLayout()); //设置关闭事件 jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //添加label Label stuClass = new Label("班级"); Label stuNo = new Label("学号"); Label stuName = new Label("姓名"); //添加文本框 final TextField tfClass = new TextField(30); final TextField tfNo = new TextField(30); final TextField tfName = new TextField(30); //添加按钮 Button confirm = new Button("确定"); Button cancel = new Button("取消"); //添加文本域 final TextArea ta = new TextArea(30,30); //添加 jf.add(stuClass); jf.add(tfClass); jf.add(stuNo); jf.add(tfNo); jf.add(stuName); jf.add(tfName); jf.add(confirm); jf.add(cancel); jf.add(ta); //添加事件 confirm.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { String stuClass = tfClass.getText().trim(); String stuNo = tfNo.getText().trim(); String stuName = tfName.getText().trim(); tfClass.setText(""); tfNo.setText(""); tfName.setText(""); ta.append("班级:"+stuClass+"\r\n"+"学号:"+stuNo+"\r\n"+"姓名:"+stuName+"\r\n"); } }); cancel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { System.exit(0); } }); //显示 jf.setVisible(true); }}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询