| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 415 人关注过本帖
标题:哥哥姐姐,帮帮我看看什么怎么回事
只看楼主 加入收藏
hbqzbl
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-12-21
结帖率:100%
收藏
 问题点数:0 回复次数:1 
哥哥姐姐,帮帮我看看什么怎么回事
编译可以但是解释执行就不可以了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import *;
import *;


public class deleteRows extends JFrame implements ActionListener
{
    private int rows = 0,cols = 0,num = 0;
    private Object rowdata[] = new Object[cols];
    private DefaultTableModel model = new DefaultTableModel();
    private JTable table = new JTable(model);
    private JTextField jtext = new JTextField(5);
    private JButton rowbutton = new JButton("Add Row");
    private JButton delbutton = new JButton("Del Row");
    public deleteRows()
    {
        setTitle("行的添加和删除举例");
        Container cp = getContentPane();
        JPanel panel1 = new JPanel();
        panel1.add(rowbutton);
        panel1.add(delbutton);
        JPanel panel2 = new JPanel();
        panel2.add(new JLabel("请输入要删除的学号"));
        panel2.add(jtext);
        model.addColumn("学号");
        model.addColumn("姓名");
        model.addColumn("学院");
        model.addColumn("班级");
        cp.add(new JScrollPane(table),BorderLayout.CENTER);
        cp.add(panel1,BorderLayout.SOUTH);
        cp.add(panel2,BorderLayout.NORTH);
        rowbutton.addActionListener(this);
        delbutton.addActionListener(this);
        setSize(300,200);
        setVisible(true);
        addWindowListener(new WindowAdapter()
                          {
                            public void windowClosing(WindowEvent e)
                              {
                                System.exit(0);
                              }
                          });
    }
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == rowbutton)
        {
            int rowCount = model.getRowCount();
            rowdata = new Object[cols];
            rowdata[0] = "A00"+(num+1);
            for (int c=1;c<cols ;++c )
            {
                rowdata[c] = "table["+rowCount+"]["+c+"]";
            }
            model.insertRow(num,rowdata);
            num++;
        }
        if (e.getSource() == delbutton)
        {
            String str = jtext.getText();
            int k = 0;
            while (k<model.getRowCount())
            {
                if (str.equals((model.getValueAt(k,0)).toString()))
                {
                    model.removeRow(k);
                    break;
                }
                k++;
            }
        }
    }
    public static void main(String args[])
    {
        new deleteRows();
    }
}
搜索更多相关主题的帖子: private Object public 
2012-04-16 10:49
hbqzbl
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-12-21
收藏
得分:0 
  没有人帮我解答啊!!!
2012-04-18 13:35
快速回复:哥哥姐姐,帮帮我看看什么怎么回事
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016133 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved