Java写一个SWT应用程序窗口包含班级姓名学号
时间: 2023-10-09 17:12:53 浏览: 46
下面是一个简单的Java SWT应用程序示例,其中包含班级、姓名和学号:
```
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class SWTApplication {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(300, 200);
shell.setText("班级姓名学号");
Label classNameLabel = new Label(shell, SWT.NONE);
classNameLabel.setText("班级: 1班");
classNameLabel.setBounds(20, 20, 100, 20);
Label nameLabel = new Label(shell, SWT.NONE);
nameLabel.setText("姓名: 张三");
nameLabel.setBounds(20, 60, 100, 20);
Label numberLabel = new Label(shell, SWT.NONE);
numberLabel.setText("学号: 20190101");
numberLabel.setBounds(20, 100, 100, 20);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
```
在上面的代码中,我们创建了一个 `Shell` 对象并设置了其大小和标题。然后,我们创建了三个 `Label` 对象,分别用于显示班级、姓名和学号。最后,我们打开窗口并进入事件循环,直到窗口被关闭。
你可以根据自己的需要修改代码以适应你的应用程序。