Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? [Re:imain]
imain





发贴: 16
积分: 0
于 2005-05-25 14:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这是原代码:

import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.sql.*;
import com.borland.dbswing.*;
import java.util.*;
import java.awt.event.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright Coffee 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class ItemPrice extends JFrame implements ActionListener {
JPanel mainP = new JPanel();
JButton okBtn=new JButton("添加");
JButton cancelBtn=new JButton("取消");
JPanel p2=new JPanel();
JLabel cate=new JLabel("用水类别");
JTextField tfCate=new JTextField(10);
JLabel price=new JLabel("单 价");
JTextField tfPrice=new JTextField(10);
public ItemPrice()
{

Container cont=getContentPane();
cont.setLayout(new FlowLayout(FlowLayout.CENTER));
cont.add(new p1());
cont.add(mainP);
p2.setLayout(new GridLayout(3,2));
p2.add(cate);
p2.add(price);
p2.add(tfCate);
p2.add(tfPrice);
p2.add(okBtn);
p2.add(cancelBtn);
mainP.add(p2);
okBtn.addActionListener(this);
cancelBtn.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==okBtn)
{
WaterDB db=new WaterDB();
String sql="insert into category(name,price) values(\'"+tfCate.getText()+"\',\'"+tfPrice.getText()+"\')";
db.executeUpdate(sql);
tfCate.setText("");
tfPrice.setText("");
}
else if(e.getSource()==cancelBtn)
{
tfCate.setText("");
tfPrice.setText("");
}
}

class p1 extends JPanel {
public p1() {
Vector cell;
Vector row = new Vector();
DefaultTableModel tableModel = new DefaultTableModel();
String[] tableHeads = {"用水类别", "单价"};
Vector tableHeadName = new Vector();
for (int i = 0; i <tableHeads.length; i++) {
tableHeadName.add(tableHeads[i]);
}
try {
WaterDB wdb = new WaterDB();
String sql = "select * from category";
ResultSet rs = wdb.executeQuery(sql);
while (rs.next()) {
cell = new Vector();
for (int i = 1; i <= tableHeads.length; i++) {
cell.add(rs.getStringLight Bulb);
}
row.add(cell);
}
tableModel.setDataVector(row, tableHeadName);
JTable table = new JTable(tableModel);
table.setFont(new Font("Dialog", 1, 13));
table.setRowHeight(20);
table.getColumn( "用水类别" ).setMaxWidth(120 ) ;
table.getColumn( "用水类别" ).setResizable( false ) ;
table.getColumn( "单价" ).setMaxWidth(80 ) ;
table.getColumn( "单价" ).setResizable( false ) ;
table.setCursor(new Cursor(12));
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setCursor(new Cursor(12));
this.add(scrollPane);
this.setVisible(true);
}
catch (SQLException f) {}
}
}
public static void main(String[] args) {
ItemPrice itemPrice = new ItemPrice();
itemPrice.setSize(280, 300);
itemPrice.show();
}
}


littledeer1974 edited on 2005-05-31 09:36


初学者与<书>

话题树型展开
人气 标题 作者 字数 发贴时间
6421 版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? imain 28 2005-05-25 14:20
5423 Re:版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? imain 3050 2005-05-25 14:21
5267 Re:版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? kavinwang 109 2005-05-25 19:18
5355 Re:版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? imain 41 2005-05-26 18:45
5189 Re:版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? kavinwang 58 2005-05-27 08:52
5302 Re:版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? imain 7 2005-05-27 20:13
5321 Re:版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? imain 6 2005-05-29 18:56
6034 Re:版主:我列宽的问题解决了,可是新的问题来了,能帮我看一下吗? kavinwang 82 2005-05-30 08:31

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923