Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help, 3-JComboBox Search algorithm !  RSS feed

 
SungChan Park
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Swing design is composed with 3-ComboBox & JTable.
I want search specific Table record which correspond to JComboBox
value. My Design (Selection.java) does not implemented "Search"
function until now.

Can anyone help me to solve this problem ?

My e-mail address is

xcom98@chollian.net

Thanks for reading !!
===================================
Selection.java
===================================
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;

/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/
public class Selection extends JFrame implements ActionListener {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JScrollPane jScrollPane1 = new JScrollPane();

JTable jTable1;

Object[][] data1 = {
{"440", "GMC-3000", "300", "GTH-600", "400-600", "GMC-150", "GMC-300", "ABS803a", "800", "200"},
{"220", "GMC-150", "150", "GTH-220", "160-240", "GMC-100", "GMC-150", "ABS403a", "400", "100"},
{"165", "GMC-150", "140", "GTH-220", "120-180", "GMC-85", "GMC-150", "ABS403a", "300", "100"},
{"528", "GMC-400", "400", "GTH-600", "400-600", "GMC-220", "GMC-400", "ABS1003a", "1000", "325"},
{"264", "GMC-180", "180", "GTH-400", "200-300", "GMC-100", "GMC-180", "ABS603a", "500", "150"},
{"198", "GMC-150", "140", "GTH-220", "160-240", "GMC-100", "GMC-150", "ABS403a", "350", "100"},

};

Object[][] data2 = {
{"440", "GMC-600", "600", "GTH-600", "400-600", "", "", "ABS803a", "800", "250"},
{"200", "GMC-220", "220", "GTH-220", "160-240", "", "", "ABS403a", "400", "150"},
{"176", "GMC-180", "180", "GTH-220", "160-240", "", "", "ABS403a", "350", "150"},
{"528", "GMS-600", "600", "GTH-600", "400-600", "", "", "ABS1003", "1000", "325"},
{"264", "GMS-300", "300", "GTH-400", "200-300", "", "", "ABS603a", "500", "200"},
{"211", "GMS-300", "250", "GTH-400", "200-300", "", "", "ABS403a", "400", "200"},
};
String[] columnNames = {"모터부하",
"전자접촉기",
"정격사용전류",
"과부하계전기",
"TOR설정",
"시동용접촉기",
"운전용접촉기",
"배선용차단기",
"정격전류",
"전선단면적"};
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();

String[] start = { "Y-Delta 기동", "직입기동"};
String[] voltage = { "200V~240V 3상 60 Hz", "380V~440V 3상 60 Hz","500V~550V 3상 60 Hz"};
String[] mt = { "110kW, 150HP", "132kW, 180HP"};
JComboBox jComboBox1 = new JComboBox(mt);
JComboBox jComboBox2 = new JComboBox(start);
JComboBox jComboBox3 = new JComboBox(voltage);



/**Construct the frame*/
public Selection() {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(800, 500));
this.setTitle("기종선정 프로그램");
jLabel1.setText("기동 조건");
jLabel2.setText("정격전압");
jLabel3.setText("모터출력");
jPanel1.add(jLabel1, null);
jPanel1.add(jComboBox2, null);
jPanel1.add(jLabel2, null);
jPanel1.add(jComboBox3, null);
jPanel1.add(jLabel3, null);
jPanel1.add(jComboBox1, null);
jPanel1.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jTable1, null);
jTable1.setPreferredScrollableViewportSize(new Dimension(790, 300));
contentPane.add(jPanel1, BorderLayout.NORTH);

jComboBox1.setSelectedIndex(0);
jComboBox2.setSelectedIndex(0);
jComboBox3.setSelectedIndex(0);

jComboBox1.addActionListener(new Eavesdropper());
jComboBox1.addActionListener(new Eavesdropper());
jComboBox1.addActionListener(new Eavesdropper());


}

/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Selection frame = new Selection();
frame.setVisible(true);
}
catch(Exception e) {
e.printStackTrace();
}
}

}
class Eavesdropper implements ActionListener {
int to;
public void actionPerformed(ActionEvent e) {

if(jComboBox2.getSelectedIndex() == 0){
to = 3* (jComboBox3.getSelectedIndex()) + jComboBox1.getSelectedIndex();

jTable1 = new JTable(data1[to][1], columnNames);
}
if(jComboBox2.getSelectedIndex() == 1){
to = 3* (jComboBox3.getSelectedIndex()) + jComboBox1.getSelectedIndex();
jTable1 = new JTable(data2[to][1], columnNames);
}
}
}
 
SungChan Park
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops !
I should modify above Selection.java file.
Sorry for trouble.
===================================
Selection.java
===================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/
public class Selection extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
String[] start = { "Y-Delta 기동", "직입기동"};
String[] voltage = { "200V~240V 3상 60 Hz", "380V~440V 3상 60 Hz","500V~550V 3상 60 Hz"};
String[] mt = { "110kW, 150HP", "132kW, 180HP"};
JComboBox jComboBox1 = new JComboBox(mt);
JComboBox jComboBox2 = new JComboBox(start);
JComboBox jComboBox3 = new JComboBox(voltage);
JScrollPane jScrollPane1 = new JScrollPane();

Object[][] data = {
{"440", "GMC-3000", "300", "GTH-600", "400-600", "GMC-150", "GMC-300", "ABS803a", "800", "200"},
{"220", "GMC-150", "150", "GTH-220", "160-240", "GMC-100", "GMC-150", "ABS403a", "400", "100"},
{"165", "GMC-150", "140", "GTH-220", "120-180", "GMC-85", "GMC-150", "ABS403a", "300", "100"},
{"528", "GMC-400", "400", "GTH-600", "400-600", "GMC-220", "GMC-400", "ABS1003a", "1000", "325"},
{"264", "GMC-180", "180", "GTH-400", "200-300", "GMC-100", "GMC-180", "ABS603a", "500", "150"},
{"198", "GMC-150", "140", "GTH-220", "160-240", "GMC-100", "GMC-150", "ABS403a", "350", "100"},
{"440", "GMC-600", "600", "GTH-600", "400-600", "", "", "ABS803a", "800", "250"},
{"200", "GMC-220", "220", "GTH-220", "160-240", "", "", "ABS403a", "400", "150"},
{"176", "GMC-180", "180", "GTH-220", "160-240", "", "", "ABS403a", "350", "150"},
{"528", "GMS-600", "600", "GTH-600", "400-600", "", "", "ABS1003", "1000", "325"},
{"264", "GMS-300", "300", "GTH-400", "200-300", "", "", "ABS603a", "500", "200"},
{"211", "GMS-300", "250", "GTH-400", "200-300", "", "", "ABS403a", "400", "200"},
};
String[] columnNames = {"모터부하",
"전자접촉기",
"정격사용전류",
"과부하계전기",
"TOR설정",
"시동용접촉기",
"운전용접촉기",
"배선용차단기",
"정격전류",
"전선단면적"};

JTable jTable1 = new JTable(data, columnNames);
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();

/**Construct the frame*/
public Selection() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(800, 500));
this.setTitle("기종선정 프로그램");
jLabel1.setText("기동 조건");
jLabel2.setText("정격전압");
jLabel3.setText("모터출력");
jPanel1.add(jLabel1, null);
jPanel1.add(jComboBox2, null);
jPanel1.add(jLabel2, null);
jPanel1.add(jComboBox3, null);
jPanel1.add(jLabel3, null);
jPanel1.add(jComboBox1, null);
jPanel1.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jTable1, null);
jTable1.setPreferredScrollableViewportSize(new Dimension(790, 300));
contentPane.add(jPanel1, BorderLayout.NORTH);
}
/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Selection frame = new Selection();
frame.setVisible(true);
}
catch(Exception e) {
e.printStackTrace();
}
}

}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!