java添加监听的作用,关于choice添加监听器的问题。为什么监听器不起作用

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package yun;

public class Position_Score{

static String cc[],gg[];

static JFrame ps;

static Label id, ln,pr,st, lb,soc;

static TextField Id;

static Button b1, b2;

JTable tab;

static Choice g,c,sc;

static JScrollPane jsp;

static Object rowData[][];

static String[] columnNames={"Id","岗位","分制类别","分值"};

static Panel north, center, p1, p2, p3,p4,p5,p6,p7;

Position_Score() {

String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

String dbURL = "jdbc:microsoft:sqlserver://localhost:1433;Databasename=bishe";

String userName = "sa";

String userPwd = "123";

Statement stmt=null;

String choice="select * from pssc";

ResultSet rs=null;

Connection dbConn=null;

int count=0;

rowData=new Object[10][4];

jsp=new JScrollPane(tab);

g= new Choice();

c= new Choice();

sc=new Choice();

// cc=new String[40];

//gg=new String[40];

try {

Class.forName(driverName);

dbConn = DriverManager.getConnection(dbURL, userName, userPwd);

stmt = dbConn.createStatement();

rs = stmt.executeQuery(choice);

while(rs.next()){

rowData[count][0]=rs.getString(1);

rowData[count][1]=rs.getString(2);

rowData[count][2]=rs.getString(3);

rowData[count][3]=rs.getString(4);

count++;

tab=new JTable(rowData,columnNames);

ps.getContentPane().add(jsp,BorderLayout.SOUTH);

}

rs.close();stmt.close();dbConn.close();

}

catch(Exception ex){

}finally{

try{if(rs!=null){rs.close();}}catch(Exception ex){}

try{if(stmt!=null){stmt.close();}}catch(Exception ex){}

try{if(dbConn!=null){dbConn.close();}}catch(Exception ex){}

}

for(int i=1;i<=13;i++){

String j=String.valueOf(i);

sc.addItem(j);

}

ps = new JFrame("岗位分值——添加");

id = new Label("ID: ");

ln = new Label("岗位: ");

pr = new Label("分值项: ");

soc= new Label("分值");

Id = new TextField(20);

b1 = new Button("确定");

b2 = new Button("取消");

lb = new Label("岗位分值列表");

north = new Panel();

center = new Panel();

p1 = new Panel();

p2 = new Panel();

p3 = new Panel();

p4 = new Panel();

p5 = new Panel();

p6 = new Panel();

b1.addActionListener(new Action_PS());

b2.addActionListener(new Action_PS());

ps.addWindowListener(new Winclose());

ps.setSize(350, 400);

ps.setLocation(540, 300);

ps.setBackground(Color.LIGHT_GRAY);

ps.setVisible(true);

p1.add(id);

p1.add(Id);

p1.setVisible(true);

g.add("");

g.addItemListener(new ItemListener(){

@Override

public void itemStateChanged(ItemEvent e) {

// TODO Auto-generated method stub

if(g.getSelectedItem().equals("")){

System.out.println("nihao");

String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

String dbURL = "jdbc:microsoft:sqlserver://localhost:1433;Databasename=bishe";

String userName = "sa";

String userPwd = "123";

Statement stmt=null;

String choice="select pname from post";

ResultSet rs=null;

Connection dbConn=null;

try {

Class.forName(driverName);

dbConn = DriverManager.getConnection(dbURL, userName, userPwd);

stmt = dbConn.createStatement();

rs = stmt.executeQuery(choice);

while(rs.next()){

String gw=rs.getString(1);

System.out.println(gw);

g.add(gw);

}

rs.close();stmt.close();dbConn.close();

}

catch(Exception ex){

}finally{

try{if(rs!=null){rs.close();}}catch(Exception ex){}

try{if(stmt!=null){stmt.close();}}catch(Exception ex){}

try{if(dbConn!=null){dbConn.close();}}catch(Exception ex){}

}

}

}

});

p2.add(ln);

p2.add(g);

p2.setVisible(true);

p4.add(pr);

p4.add(c);

p4.setVisible(true);

p4.add(soc);

p4.add(sc);

p4.setVisible(true);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值