一个小桌面的java代码 java桌面gui( 二 )


addBtnLoginActionListener();
}
});
getContentPane().add(btnLogin);
btnClose = new JButton();
btnClose.setText("关闭");
btnClose.setBounds(175, 142, 85, 28);
btnClose.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
System.exit(-1);
}
});
getContentPane().add(btnClose);
}
private void addBtnLoginActionListener() {
String user = t_Id.getText();
String password = new String(t_pw.getPassword());
if (user.equals("")) {
JOptionPane.showMessageDialog(this, "帐号不可为空", "Caution",
JOptionPane.WARNING_MESSAGE);
return;
}
if (password.equals("")) {
JOptionPane.showMessageDialog(this, "密码不可为空", "Caution",
JOptionPane.WARNING_MESSAGE);
return;
}
String sql = "select * FROM login WHERE id = '" + user + "' and pw = '"
+ password + "'";
boolean success = false;
// TODO:数据校验 success = executeQuery(sql);
if (success) {
// TODO: 如果数据校验成功 显示主界面 并关闭登录界面
JOptionPane.showMessageDialog(this, "成功登录", "提示",
JOptionPane.INFORMATION_MESSAGE);
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "帐号或密码错误!", "警告",
JOptionPane.WARNING_MESSAGE);
t_pw.requestFocus(); // 密码框选中
}
}
public Dimension getPreferredSize() {
return new Dimension(320, 170);
}
public void show() {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screen = tk.getScreenSize();
Dimension d = getSize();
this.setLocation((screen.width - d.width) / 2,
(screen.height - d.height) / 2);
// 输入密码后回车相当于点击了登录按钮
getRootPane().setDefaultButton(btnLogin);
t_pw.requestFocus();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setSize(300, 220);
super.show();
}
public static void main(String[] args) {
vv loginFrame = new vv();
loginFrame.setVisible(true);
}
}
希望对你有帮助
谁有Java桌面面板的教程,因为书上的代码错误,求高手给个能运行无错的代码一个小桌面的java代码我运行一个小桌面的java代码的是对的 。题主报的什么错?
BTW 题主把back.jpg放在正确的位置一个小桌面的java代码了吗?
Java程序:创建一个桌子(Table)类 , 该类中有桌子名称、重量、桌面宽度、长度和桌子高度属性,以及以下几个package com.kaylves;
public class Table {
private String tableName;//名称
private int weight;//重量
private int length; //长度
private int height; //高度
private int width;//宽度
public Table(){
tableName="";
}
public Table(String tableName,int weight,int length,int height,int width){
this.tableName=tableName;
this.weight=weight;
this.length=length;
this.height=height;
this.width=width;
【一个小桌面的java代码 java桌面gui】 }
public int getArea(){
return length*width;
}
public void display(){
System.out.println("桌名称:"+this.tableName);
System.out.println("重量:"+this.weight);
System.out.println("长度:"+this.length);
System.out.println("高度:"+this.height);
System.out.println("宽度:"+this.width);
System.out.println("面积:"+this.getArea());
}
public void changeWeight(int w){
this.weight=w;
}
public static void main(String[] args){
Table table = new Table("小桌子",20,50,20,20);
int area=table.getArea();
table.changeWeight(30);
table.display();
}
}
写了一段java代码 , 怎么让它以桌面程序的形式运行?1.

推荐阅读