JAVA用frame实现图中2个窗口 怎么写?。?/h2>图片看起来很模糊java编程窗口代码图片,隐约看到需要一个登录窗口java编程窗口代码图片,那就分享一下以前练习的登录窗口demo吧 。
先上效果图java编程窗口代码图片:
登录界面
源码如下java编程窗口代码图片:
AbsoluteLoginFrame.java
public class AbsoluteLoginFrame extends JFrame {
private static final int LOGIN_WIDTH = 600;
private static final int LOGIN_HEIGHT = 400;
private static final long serialVersionUID = -2381351968820980500L;
public AbsoluteLoginFrame(){
//设置窗口标题
setTitle("登录界面");
//设置一个初始面板java编程窗口代码图片,填充整个窗口
JPanel loginPanel = new JPanel();
//设置背景颜色
loginPanel.setBackground(new Color(204, 204, 204));//#CCC
loginPanel.setLayout(null);
JPanel centerPanel = new JPanel();
centerPanel.setBackground(Color.WHITE);
centerPanel.setBounds(114, 70, 360, 224);
centerPanel.setLayout(null);
JLabel jLabel = new JLabel("用户名:");
jLabel.setOpaque(true);
jLabel.setBackground(Color.YELLOW);
jLabel.setBounds(60, 60, 54, 20);
JLabel label = new JLabel("密码:");
label.setOpaque(true);
label.setBackground(Color.CYAN);
label.setBounds(60, 90, 54, 20);
JTextField textField = new JTextField(15);
textField.setBounds(130, 60, 166, 21);
JPasswordField passwordField = new JPasswordField(15);
passwordField.setBounds(130, 90, 166, 21);
JButton jButton = new JButton("登录");
jButton.setBounds(148, 120, 62, 28);
centerPanel.add(jLabel);
centerPanel.add(label);
centerPanel.add(textField);
centerPanel.add(jButton);
centerPanel.add(passwordField);
loginPanel.add(centerPanel);
getContentPane().add(loginPanel);//将初始面板添加到窗口中
setSize(LOGIN_WIDTH, LOGIN_HEIGHT);//设置窗口大小
setLocation(Screen.getCenterPosition(LOGIN_WIDTH, LOGIN_HEIGHT));//设置窗口位置
setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口默认关闭方式
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
new AbsoluteLoginFrame();
}
}
Screen.java
public class Screen {
private int width;
private int height;
public Screen(){
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
this.width = screenSize.width;
this.height = screenSize.height;
}
public static Point getCenterPosition(int width, int height){
Screen screen = new Screen();
int x = (screen.getWidth() - width) / 2;
int y = (screen.getHeight() - height) / 2;
return new Point(x, y);
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
java编程 完成下图所示的图形用户界面设计(窗口标题为你的真实学号及姓名,例如:11930670好像是作业, 源代码发给你参考,注意学习下代码.了解下布局 和按钮的工作原理
参考代码
import java.awt.*;
import java.awt.event.*;
public class MyRandomFrame extends Frame implements ActionListener {
private final TextField tf1;
private final TextField tf2;
private final TextField tf3;
public static void main(String[] args) {
new MyRandomFrame().setVisible(true);
}
public MyRandomFrame() {
setSize(600, 100);
setLocationRelativeTo(null);
setTitle("学号:XXXXX姓名:张三");
Button but1 = new Button("获取1~100之间的随机数");
推荐阅读
- ppt如何预览演示文稿,ppt中的预览窗格怎么搞
- u盘里有歌怎么删除,u盘中的歌怎么删除
- jquery数字换成日期格式,jquery 数字转字符串
- java代码注释优雅 java的注释怎么写
- flutter实现个人资料页面,flutter 个人中心
- linux进入管理员命令,linux如何进入命令
- 动态修改需要加载的js,js文件加动态版本号问题
- python下载库函数 python库下载地址
- 手机不显示团购链接怎么办,抖音不显示团购链接