用Java创建一个窗口,输入你的学号、姓名,选择所在班级(班级以下拉列表的形式给出,共5个班,软件1--软件5),完成信息填写后,点击按钮,弹出对话框,该提示框显示你的学号、姓名和班级,以及确定按钮,点击确定按钮,对话框消失;关闭窗口。这个该怎么写?
创建一个窗口,输入你的学号、姓名,选择所在班级,完成信息填写后,点击按钮,弹出对话框,该提示框显示你的学号、姓名和班级,以及确定按钮,点击确定按钮,对话框消失;关闭窗口。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- HelloWorldZTR 2020-05-01 10:22关注
我太懒了...
package com.hlwdztr; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class Test { private Label xuehaoLb; private Label xingmingLb; private Label banjiLb; private Dialog info; private Frame frame; private TextField xuehao; private TextField xingming; private Choice banji; private Button okButton; private String[] ban = {"软件1","软件2","软件3","软件4","软件5"}; public Test(){ xuehaoLb = new Label("学号",Label.CENTER); xingmingLb = new Label("姓名",Label.CENTER); banjiLb = new Label("班级",Label.CENTER); frame = new Frame("窗口"); xuehao = new TextField(); xingming = new TextField(); banji = new Choice(); okButton = new Button("确定"); info = new Dialog(frame); } private void showInfo(){ String xuehaoStr = xuehao.getText(); String xingmingStr = xingming.getText(); String banjiStr = banji.getSelectedItem(); Button okButton2 = new Button("确定"); okButton2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); info.setTitle("对话框"); info.setLayout(new BorderLayout()); info.add(BorderLayout.CENTER, new Label("姓名是"+xingmingStr+'\t'+"班级是"+banjiStr+'\t'+"学号是"+xuehaoStr)); info.add(BorderLayout.SOUTH, okButton2); info.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); info.pack(); info.setAlwaysOnTop(true); info.setVisible(true); } public void show(){ for (String item : ban) { banji.addItem(item); } okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showInfo(); } }); frame.setLayout(new GridLayout(4,2)); frame.add(xuehaoLb); frame.add(xuehao); frame.add(xingmingLb); frame.add(xingming); frame.add(banjiLb); frame.add(banji); frame.add(okButton); // frame.pack(); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setSize(200, 150); frame.setVisible(true); } public static void main(String[] args) { Test test = new Test(); test.show(); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用
悬赏问题
- ¥15 乌班图ip地址配置及远程SSH
- ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
- ¥15 PSPICE制作一个加法器
- ¥15 javaweb项目无法正常跳转
- ¥15 VMBox虚拟机无法访问
- ¥15 skd显示找不到头文件
- ¥15 机器视觉中图片中长度与真实长度的关系
- ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
- ¥15 java 的protected权限 ,问题在注释里
- ¥15 这个是哪里有问题啊?