public class Frame extends javax.swing.JFrame {
TableModel model = new TableModel()
/** Creates new form Frame */
public Frame() {
initComponents()
this.jTable1.setModel(model)
}
class TableModel extends AbstractTableModel {
String[] values = {"乌龟", "海龟", "鸵鸟", "老鸟"}
private int n = 3
@Override
public int getRowCount() {
return (n + 1) * 2
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true
}
public void setIndex(int n) {
this.n = n
this.fireTableStructureChanged()
}
@Override
public int getColumnCount() {
return (n + 1) * 2
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return values[n]
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane()
jTable1 = new javax.swing.JTable()
jPanel1 = new javax.swing.JPanel()
乌龟 = new javax.swing.JButton()
海龟 = new javax.swing.JButton()
鸵鸟 = new javax.swing.JButton()
老鸟 = new javax.swing.JButton()
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE)
jScrollPane1.setName("jScrollPane1")// NOI18N
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
))
jTable1.setName("jTable1")// NOI18N
jScrollPane1.setViewportView(jTable1)
jPanel1.setName("jPanel1")// NOI18N
乌龟.setText("乌龟")
乌龟.setName("乌龟")// NOI18N
乌龟.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
乌龟ActionPerformed(evt)
}
})
海龟.setText("海龟")
海龟.setName("海龟")// NOI18N
海龟.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
海龟ActionPerformed(evt)
}
})
鸵鸟.setText("鸵鸟")
鸵鸟.setName("鸵鸟")// NOI18N
鸵鸟.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
鸵鸟ActionPerformed(evt)
}
})
老鸟.setText("老鸟")
老鸟.setName("老鸟")// NOI18N
老鸟.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
老鸟ActionPerformed(evt)
}
})
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1)
jPanel1.setLayout(jPanel1Layout)
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(乌龟)
.addGap(18, 18, 18)
.addComponent(海龟)
.addGap(18, 18, 18)
.addComponent(鸵鸟)
.addGap(18, 18, 18)
.addComponent(老鸟)
.addContainerGap(117, Short.MAX_VALUE))
)
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(乌龟)
.addComponent(海龟)
.addComponent(鸵鸟)
.addComponent(老鸟))
.addContainerGap(16, Short.MAX_VALUE))
)
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane())
getContentPane().setLayout(layout)
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
)
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE))
)
pack()
}// </editor-fold>
private void 乌龟ActionPerformed(java.awt.event.ActionEvent evt) {
model.setIndex(0)
}
private void 海龟ActionPerformed(java.awt.event.ActionEvent evt) {
model.setIndex(1)
}
private void 鸵鸟ActionPerformed(java.awt.event.ActionEvent evt) {
model.setIndex(2)
}
private void 老鸟ActionPerformed(java.awt.event.ActionEvent evt) {
model.setIndex(3)
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Frame().setVisible(true)
}
})
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1
private javax.swing.JScrollPane jScrollPane1
private javax.swing.JTable jTable1
private javax.swing.JButton 乌龟
private javax.swing.JButton 海龟
private javax.swing.JButton 老鸟
private javax.swing.JButton 鸵鸟
// End of variables declaration
}
用数组或集合来接受这个答案,使用 题号id_选项id 这种格式传值,接受完以后,拆分,可以再用正则来判断是不是这种格式的,一般像这种问卷类的,要是还要获取答案,最好把答案放到json里,然后存到数据库,json的格式就可以题号,选项这种格式存储,到时候拿的时候也方便欢迎分享,转载请注明来源:内存溢出
评论列表(0条)