当前位置: 技术问答>在线高分急救,急救,急救,急救,急救,急救!!!!!!!!!!
iis7站长之家
急救!!!!!!
来源: 互联网 发布时间:2015-05-11
本文导语: 怎样在JTable中得到一个已选取单元的row,Column值(即这个单元在第几行,第几列),请各位大侠帮忙. 另外谁能提供一个网吧管理软件的JBuilder 源代码给我,我将不胜感激,并有300分相赠 | 我这个程序...
怎样在JTable中得到一个已选取单元的row,Column值(即这个单元在第几行,第几列),请各位大侠帮忙.
另外谁能提供一个网吧管理软件的JBuilder 源代码给我,我将不胜感激,并有300分相赠
另外谁能提供一个网吧管理软件的JBuilder 源代码给我,我将不胜感激,并有300分相赠
|
我这个程序可以判断一下表格单元的所在行数,至于列数你自己改改看吧。
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
// main class, starting of application
public class Components
{
public static void main(String[] args)
{
JFrame jf=new TableFrame();
}
}
// table model class, set tabel model and initialize table's data
class ReviewTableModel extends AbstractTableModel
{
// take over tabledata class instance
private static TableData tabledata=new TableData();
// take over table column's name
String[] columnName=tabledata.columnName;
// take over table row's data
private Object[][] rowData=tabledata.rowData;
// implement 3 methods which AbstractTableModel class don't implement
public int getColumnCount()
{
return columnName.length;
}
public int getRowCount()
{
return rowData.length;
}
public Object getValueAt(int row,int col)
{
return rowData[row][col];
}
// override 4 methods which AbstractTableModel class has already implemented
public String getColumnName(int col)
{
return columnName[col];
}
public Class getColumnClass(int col)
{
return rowData[0][col].getClass();
}
public void setValueAt(Object obj,int row,int col)
{
rowData[row][col]=obj;
}
public boolean isCellEditable(int row,int col)
{
if (col==0)
{
return true;
}
else
{
return false;
}
}
}
// table cell renderer
class MyTableCellRenderer implements TableCellRenderer
{
public Component getTableCellRendererComponent
(
JTable table,Object value,boolean isSelected,
boolean hasFocus,final int row,int column
)
{
button.setText(new Integer(row+1).toString());
button.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.out.println(row+1);
}
}
);
return button;
}
/* the following panel is returned for all cells, with
the background color set to the Color value of the cell
*/
private JButton button=new JButton();
}
// table cell editor
class MyTableCellEditor implements TableCellEditor
{
public Component getTableCellEditorComponent
(
JTable table,Object obj,boolean isSelected,int row,int column
)
{
return new MyTableCellRenderer().
getTableCellRendererComponent(table,obj,isSelected,true,row,column);
}
// implement all methods in TableCellEditor interface
public boolean isCellEditable(EventObject anEvent)
{
return true;
}
public boolean shouldSelectCell(EventObject anEvent)
{
return true;
}
public void cancelCellEditing()
{
}
public boolean stopCellEditing()
{
return true;
}
public Object getCellEditorValue()
{
return null;
}
public void addCellEditorListener(CellEditorListener l)
{
}
public void removeCellEditorListener(CellEditorListener l)
{
}
protected void fireEditingStopped()
{
}
protected void fireEditingCanceled()
{
}
}
class TableData
{
private int questionCount=59;
String[] columnName;
Object[][] rowData;
Integer[] questionNumber;
String[] questionType;
String[] attempted;
Boolean[] unAttempted;
Boolean[] isMarked;
TableData()
{
initTableData();
}
void initTableData()
{
// initialize array data of table column's name
columnName=new String[]{"No.","Type","Attempted","UnAttempted","Marked"};
// initialize array data of question number column
questionNumber=new Integer[questionCount];
for(int i=0;i
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
// main class, starting of application
public class Components
{
public static void main(String[] args)
{
JFrame jf=new TableFrame();
}
}
// table model class, set tabel model and initialize table's data
class ReviewTableModel extends AbstractTableModel
{
// take over tabledata class instance
private static TableData tabledata=new TableData();
// take over table column's name
String[] columnName=tabledata.columnName;
// take over table row's data
private Object[][] rowData=tabledata.rowData;
// implement 3 methods which AbstractTableModel class don't implement
public int getColumnCount()
{
return columnName.length;
}
public int getRowCount()
{
return rowData.length;
}
public Object getValueAt(int row,int col)
{
return rowData[row][col];
}
// override 4 methods which AbstractTableModel class has already implemented
public String getColumnName(int col)
{
return columnName[col];
}
public Class getColumnClass(int col)
{
return rowData[0][col].getClass();
}
public void setValueAt(Object obj,int row,int col)
{
rowData[row][col]=obj;
}
public boolean isCellEditable(int row,int col)
{
if (col==0)
{
return true;
}
else
{
return false;
}
}
}
// table cell renderer
class MyTableCellRenderer implements TableCellRenderer
{
public Component getTableCellRendererComponent
(
JTable table,Object value,boolean isSelected,
boolean hasFocus,final int row,int column
)
{
button.setText(new Integer(row+1).toString());
button.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.out.println(row+1);
}
}
);
return button;
}
/* the following panel is returned for all cells, with
the background color set to the Color value of the cell
*/
private JButton button=new JButton();
}
// table cell editor
class MyTableCellEditor implements TableCellEditor
{
public Component getTableCellEditorComponent
(
JTable table,Object obj,boolean isSelected,int row,int column
)
{
return new MyTableCellRenderer().
getTableCellRendererComponent(table,obj,isSelected,true,row,column);
}
// implement all methods in TableCellEditor interface
public boolean isCellEditable(EventObject anEvent)
{
return true;
}
public boolean shouldSelectCell(EventObject anEvent)
{
return true;
}
public void cancelCellEditing()
{
}
public boolean stopCellEditing()
{
return true;
}
public Object getCellEditorValue()
{
return null;
}
public void addCellEditorListener(CellEditorListener l)
{
}
public void removeCellEditorListener(CellEditorListener l)
{
}
protected void fireEditingStopped()
{
}
protected void fireEditingCanceled()
{
}
}
class TableData
{
private int questionCount=59;
String[] columnName;
Object[][] rowData;
Integer[] questionNumber;
String[] questionType;
String[] attempted;
Boolean[] unAttempted;
Boolean[] isMarked;
TableData()
{
initTableData();
}
void initTableData()
{
// initialize array data of table column's name
columnName=new String[]{"No.","Type","Attempted","UnAttempted","Marked"};
// initialize array data of question number column
questionNumber=new Integer[questionCount];
for(int i=0;i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!