初学JAVA 各位帮忙看下,我的确定和关闭按钮如何才能添加上去
package frame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;import javax.swing.border.*;import bean.db;
import java.sql.*;
public class Bb {
public static void main(String[] args)
{
new WindowBox();
}
}
class WindowBox extends Frame
{
Label lab1,lab2,lab3,lab4,lab5,lab6,lab7,lab8,lab9,lab10;
Choice cho1;
TextField text1,text2,text3;
Button b1,b2;
Panel p1,p2;
String s1=null;
String s2=null;
String s3=null;
String s4=null;
String s5=null;
String s6=null;
String s7=null;
String s8=null;
WindowBox()
{
String s="select * from kc ";
db a=new db();
ResultSet rs=a.find(s);
try {
if(rs.next()){
s1=rs.getString("id");
s2=rs.getString("name");
s3=rs.getString("chandi");
s4=rs.getString("danjia");
s5=rs.getString("kucunjine");
s6=rs.getString("guige");
s7= rs.getString("jiancheng");
s8= rs.getString("kucunshuliang");
}
} catch (SQLException e) {
e.printStackTrace();
}
this.setBounds(200, 200, 400, 300);
this.setLayout(null);
p1=new Panel();
p1.setBounds(10, 30, 380, 210);
p2=new Panel();
p2.setBounds(10, 140, 380, 60);
p1.setLayout(null);
p2.setLayout(null);
lab1=new Label("商品名称");
lab1.setBounds(40 , 10, 50, 20);
p1.add(lab1);
lab2=new Label("产地");
lab2.setBounds(40 , 40, 50, 20);
p1.add(lab2);
lab3=new Label("单价");
lab3.setBounds(40 , 70, 50, 20);
p1.add(lab3);
lab4=new Label("库存金额");
lab4.setBounds(40, 100, 50, 20);
p1.add(lab4);
lab5=new Label("规格");
lab5.setBounds(240, 10, 50, 20);
p1.add(lab5);
lab6=new Label("简称");
lab6.setBounds(240, 40, 50, 20);
p1.add(lab6);
lab7=new Label("库存数量");
lab7.setBounds(240, 70, 50, 20);
p1.add(lab7);
cho1=new Choice();
cho1.setBounds(90, 10, 120, 60);
cho1.add(s2);
p1.add(cho1);
lab8=new Label();
lab8.setBounds(90, 40, 50, 20);
lab8.setText(s3);
p1.add(lab8);
text1=new TextField();
text1.setBounds(90, 70, 90, 20);
text1.setText(s4);
p1.add(text1);
text2=new TextField();
text2.setBounds(90, 100, 90, 20);
text2.setText(s5);
p1.add(text2);
lab9=new Label();
lab9.setBounds(300, 10, 50, 20);
lab9.setText(s6);
p1.add(lab9);
lab10=new Label();
lab10.setBounds(300, 40, 50, 20);
lab10.setText(s7);
p1.add(lab10);
text3=new TextField();
text3.setBounds(300, 70, 90, 20);
text3.setText(s8);
p1.add(text3);
b1=new Button("确定 ");
b1.setBounds(10, 140, 50, 50);
p2.add(b1);
b2=new Button("关闭");
b2.setBounds(40, 140, 50, 50);
p2.add(b2);
this.add(p1);
this.add(p2);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
setBounds(120,125,600,250);
this.validate();
setVisible(true);
}
}
package frame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;import javax.swing.border.*;import bean.db;
import java.sql.*;
public class Bb {
public static void main(String[] args)
{
new WindowBox();
}
}
class WindowBox extends Frame
{
Label lab1,lab2,lab3,lab4,lab5,lab6,lab7,lab8,lab9,lab10;
Choice cho1;
TextField text1,text2,text3;
Button b1,b2;
Panel p1,p2;
String s1=null;
String s2=null;
String s3=null;
String s4=null;
String s5=null;
String s6=null;
String s7=null;
String s8=null;
WindowBox()
{
String s="select * from kc ";
db a=new db();
ResultSet rs=a.find(s);
try {
if(rs.next()){
s1=rs.getString("id");
s2=rs.getString("name");
s3=rs.getString("chandi");
s4=rs.getString("danjia");
s5=rs.getString("kucunjine");
s6=rs.getString("guige");
s7= rs.getString("jiancheng");
s8= rs.getString("kucunshuliang");
}
} catch (SQLException e) {
e.printStackTrace();
}
this.setBounds(200, 200, 400, 300);
this.setLayout(null);
p1=new Panel();
p1.setBounds(10, 30, 380, 210);
p2=new Panel();
p2.setBounds(10, 140, 380, 60);
p1.setLayout(null);
p2.setLayout(null);
lab1=new Label("商品名称");
lab1.setBounds(40 , 10, 50, 20);
p1.add(lab1);
lab2=new Label("产地");
lab2.setBounds(40 , 40, 50, 20);
p1.add(lab2);
lab3=new Label("单价");
lab3.setBounds(40 , 70, 50, 20);
p1.add(lab3);
lab4=new Label("库存金额");
lab4.setBounds(40, 100, 50, 20);
p1.add(lab4);
lab5=new Label("规格");
lab5.setBounds(240, 10, 50, 20);
p1.add(lab5);
lab6=new Label("简称");
lab6.setBounds(240, 40, 50, 20);
p1.add(lab6);
lab7=new Label("库存数量");
lab7.setBounds(240, 70, 50, 20);
p1.add(lab7);
cho1=new Choice();
cho1.setBounds(90, 10, 120, 60);
cho1.add(s2);
p1.add(cho1);
lab8=new Label();
lab8.setBounds(90, 40, 50, 20);
lab8.setText(s3);
p1.add(lab8);
text1=new TextField();
text1.setBounds(90, 70, 90, 20);
text1.setText(s4);
p1.add(text1);
text2=new TextField();
text2.setBounds(90, 100, 90, 20);
text2.setText(s5);
p1.add(text2);
lab9=new Label();
lab9.setBounds(300, 10, 50, 20);
lab9.setText(s6);
p1.add(lab9);
lab10=new Label();
lab10.setBounds(300, 40, 50, 20);
lab10.setText(s7);
p1.add(lab10);
text3=new TextField();
text3.setBounds(300, 70, 90, 20);
text3.setText(s8);
p1.add(text3);
b1=new Button("确定 ");
b1.setBounds(10, 140, 50, 50);
p2.add(b1);
b2=new Button("关闭");
b2.setBounds(40, 140, 50, 50);
p2.add(b2);
this.add(p1);
this.add(p2);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
setBounds(120,125,600,250);
this.validate();
setVisible(true);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货