swing(一) 博客分类: java SwingJava
程序员文章站
2024-03-16 11:06:52
...
/** * */ package com.cw.swing; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.WindowConstants; public class LoginFrame extends JFrame{ /** * @param args */ public static void main(String[] args) { javax.swing.JFrame jframe = new javax.swing.JFrame(); jframe.setTitle("登录窗口"); jframe.setSize(400, 400); // 获取工具箱 Toolkit toolkit = Toolkit.getDefaultToolkit(); // 获取Dimension对象,包含屏幕信息 Dimension dimenson = toolkit.getScreenSize(); // 让frame居中显示 jframe.setLocation((dimenson.width - jframe.getWidth()) / 2, (dimenson.height - jframe.getHeight()) / 2); jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jframe.setLayout(new BorderLayout()); JButton btn = new JButton(); btn.setName("login"); btn.setText("登录"); LoginFrame lf = new LoginFrame(); btn.addActionListener(lf.new btnClass(lf)); JLabel lblName=new JLabel(); lblName.setName("lblName"); lblName.setText("用户名:"); JLabel lblPass=new JLabel(); lblPass.setName("lblPass"); lblPass.setText("密码:"); //JTextField txtName=new JTextField(); JTextField txtName=new JTextField(20); txtName.setName("txtName"); JTextField txtPass=new JTextField(20); txtPass.setName("txtPass"); //text.setDocument(new NumberLenghtLimitedDmt(7)); //txtName.setVisible(true); //txtName.setName("txtName"); JPanel panel = new JPanel(); panel.add(lblName); panel.add(txtName); panel.add(lblPass); panel.add(txtPass); //panel.add("asasas",panel); panel.add(btn); jframe.getContentPane().add(panel); jframe.setResizable(false); jframe.setVisible(true); } class btnClass implements ActionListener { LoginFrame lf; public btnClass(LoginFrame lf) { this.lf = lf; } public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(null, "aaa"); //lf.setVisible(false); //Main main=new Main(); //main.setVisible(true); } } }
上一篇: 二次回归和线性回归的拟合效果的对比
推荐阅读
-
swing(一) 博客分类: java SwingJava
-
将类文件打包生成jar文件 博客分类: java
-
Java中的正则匹配 博客分类: Java JavaSwingXMLHTML
-
多对一单向关联 博客分类: hibernate 多对一单向关联
-
用DWR写的一个无刷新分页 博客分类: AJAX dwr
-
times,upto,downto,each,step示例 博客分类: ruby Java
-
times,upto,downto,each,step示例 博客分类: ruby Java
-
java mail 博客分类: java Java
-
使用java.util.regex.*包验证email 博客分类: java JavaBlog
-
Cannot run program jad 博客分类: Java AndroidEclipseJDKWindowsC