大家好!请教一个程序如何设计的问题 大家用过Ethereal这个网络分析软件么?现在我要做一个程序,用到的界面和它差不多,即用表格显示一行行的内容,鼠标点击某一行时,下方的面板会显示和该行相关的内容,现在不知道用JAVA该如何下手呵,请教大家了,该使用swing中的哪些组件,怎么完成呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那个没用过不过用JLabel JTextArea再加些代码可以实现那样的 主要是鼠标Event 应该用JTable,不过要重写一些方法 package table;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.table.DefaultTableModel;/** * * @author Administrator */public class NewJFrame extends javax.swing.JFrame { /** Creates new form NewJFrame */ DefaultTableModel myTableModel; public NewJFrame() { myTableModel = new DefaultTableModel( new Object[][]{ {"11111", "22222", "33333", "44444"}, {"aaaaa", "bbbbb", "ccccc", "dddddd"}, {"qqqqq", "wwwww", "eeeee", "rrrrr"}, {"yyyy", "uuuuu", "iiiii", null} }, new String[]{ "Title 1", "Title 2", "Title 3", "Title 4" }); initComponents(); jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int i =jTable1.getSelectedRow(); jTextArea1.setText("you just selected row NO."+i); } }); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTable1.setModel(myTableModel); jScrollPane1.setViewportView(jTable1); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane2.setViewportView(jTextArea1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(15, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE) .addContainerGap()) ); pack(); }// </editor-fold> /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NewJFrame().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTable jTable1; private javax.swing.JTextArea jTextArea1; // End of variables declaration} 求详细的解释 为什么保存不上cookie?? 初学者问题 100分问一个线程同步问题,在线等.谢谢! 如何将InputStream转换成Image,并返回给Applet? JTable 单元格不能响应键盘输入 --- java中如何判断一个字符串中是否包含另一个子串----- 做界面的一些问题? 请高手进来帮忙看看我的程序哪里出问题!为什么不执行构造函数! 关于*.JDR的问题? 小弟需要帮助! 初学者问题
package table;import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;/**
*
* @author Administrator
*/
public class NewJFrame extends javax.swing.JFrame { /** Creates new form NewJFrame */
DefaultTableModel myTableModel; public NewJFrame() {
myTableModel = new DefaultTableModel(
new Object[][]{
{"11111", "22222", "33333", "44444"},
{"aaaaa", "bbbbb", "ccccc", "dddddd"},
{"qqqqq", "wwwww", "eeeee", "rrrrr"},
{"yyyy", "uuuuu", "iiiii", null}
},
new String[]{
"Title 1", "Title 2", "Title 3", "Title 4"
});
initComponents();
jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int i =jTable1.getSelectedRow();
jTextArea1.setText("you just selected row NO."+i);
}
});
} /** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTable1.setModel(myTableModel);
jScrollPane1.setViewportView(jTable1); jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane2.setViewportView(jTextArea1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(15, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
.addContainerGap())
); pack();
}// </editor-fold> /**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
new NewJFrame().setVisible(true);
}
});
} // Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}