import java.awt.BorderLayout
import java.awt.Dimension
import java.awt.Font
import java.awt.Graphics
import java.awt.GridLayout
import java.awt.Image
import java.awt.Toolkit
import java.awt.event.ActionEvent
import java.awt.event.FocusEvent
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.awt.event.WindowEvent
import java.sql.Connection
import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.Statement
import javax.swing.ImageIcon
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JOptionPane
import javax.swing.JPanel
import javax.swing.JPasswordField
import javax.swing.JTextField
import javax.swing.UIManager
import javax.swing.UnsupportedLookAndFeelException
import javax.swing.plaf.multi.MultiLookAndFeel
import pack_DB.DB
public class Login extends JFrame{
/**
* 登陆界面
*/
private static final long serialVersionUID = 1L
JFrame jf = new JFrame()
private JPanel panel_all
private JPanel panel1 = new JPanel()
private JPanel panel2= new JPanel()
private JPanel panel3 = new JPanel()
private JPanel panel4 = new JPanel()
private JLabel jLabel_title
private JLabel jLabel_name = new JLabel()
private JLabel jLabel_password = new JLabel()
private JTextField jTextField_name = new JTextField(15)
private JPasswordField jPasswordField = new JPasswordField(15)
private JButton jb1 = new JButton()
private JButton jb2 = new JButton()
private Font font
String cid=""
String passwd =""
//加载背景图片
//脊衡 private ImageIcon imageicon
// private Image image
public Login() {
jf.setTitle("客运野信户端登陆")
jf.setSize(350, 300)
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize()//旁轮把用户的显示器屏幕的尺寸(长和宽)赋值给变量screenSize
Dimension frameSize = jf.getSize()
if (frameSize.height >screenSize.height) {
frameSize.height = screenSize.height
}
if (frameSize.width >screenSize.width) {
frameSize.width = screenSize.width
}
//把d出的对话框窗口放置在屏幕中间
jf.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2)
// imageicon = new ImageIcon(ClassLoader
//.getSystemResource("res/backgound.jpg".toString()))
panel_all = new JPanel(){
public void paintComponent(Graphics g){
super.paintComponents(g)
//image = imageicon.getImage()
//if(image != null)
//g.drawImage(image,0,0,getWidth(),getHeight(),this)
}
}
font=new Font("宋体正文", 0,20)
jLabel_title = new JLabel(new ImageIcon(ClassLoader
.getSystemResource("res/Login.jpg".toString())))
jLabel_title.setFont(font)
jLabel_title.setText("用户登陆")
jLabel_name.setFont(new java.awt.Font("Dialog", 0, 14))
jLabel_name.setText("用户名:")
jLabel_password.setFont(new java.awt.Font("Dialog", 0, 14))
jLabel_password.setText("密 码:")
jb1.setFont(new java.awt.Font("Dialog", 0, 18))
jb1.setText("确认")
jb2.setText("取消")
jb2.setFont(new java.awt.Font("Dialog", 0, 18))
jTextField_name.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
jb1.doClick()
}
}})
jPasswordField.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
jb1.doClick()
}
}})
panel1.add(jLabel_name)
panel1.add(jTextField_name)
panel2.add(jLabel_password)
panel2.add(jPasswordField)
panel3.add(jb1)
panel3.add(jb2)
panel4.add(jLabel_title)
panel_all.setLayout(new GridLayout(4,1))
panel_all.add(panel4)
panel_all.add(panel1)
panel_all.add(panel2)
panel_all.add(panel3)
panel_all.setOpaque(false)
jf.setLayout(new BorderLayout())
jf.add(panel_all)
jb1.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
// if(lc.validate(jTextField_name.getText().trim(),new String(jPasswordField.getPassword()).trim())){
// doLogin()
//new MainFrame()
//}
//else
// JOptionPane.showMessageDialog(null, "Password doesn't match account,please try again!")
}
})
jb2.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
System.exit(0)
}
})
jf.setVisible(true)
jf.repaint()
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
}
/* public void doLogin(){
cid=jTextField_name.getText().trim()
passwd=jPasswordField.getText().trim()
String sql = "select *from customer where "+"cid='"+cid+"' and password='"+passwd+"'"
if (DB.connectDB()) {
if (DB.query(sql)){
System.out.print("登陆成功")
jf.dispose()
new MainFrame(cid)
return
} else {
System.out.print("登陆失败")
return
}
}
}
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Login()
}
}
新建一个窗口,然后实现一个关闭按钮”窗口的功能
import java.awt.*import java.awt.event.*
public 闹晌class TestWindowEvent {
public static void main (String[] args) {
new Frame88 ("WindowAdapter")
}
}
class Frame88 extends Frame {
Frame88 (String s) {
super(s)
setBounds (300,300,200,70)
setLayout (null)
setVisible (true)
老孙 addWindowListener (new WindowAdapter() 液含锋{
public void windowClosing(WindowEvent e) {
setVisible (false)
System.exit(0)
}
} )
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)