Hi all,
I've created a GUI layout for what I am supposed to do. I have 2 combo boxes in the GUI and both serves the same function. The both of them needs to be able to drop-down the list of files from one of my folders. Hence, I just have to make one of the combo boxes to work and use the same codes for the other. At the same time, the combo box would need to allow multiple selections, How do I do that?
would be thankful if anyone could offer me some help.
below are my codes:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Layout extends JFrame {
Layout() {
//add radio buttons
final JRadioButton query1, query2, query3, target1, target2, target3;
query1 = new JRadioButton();
query1.setLayout(new FlowLayout());
query1.add(new JTextField(15));
query1.add(new JButton("Upload"));
query1.setSelected(true);
query2 = new JRadioButton();
query2.setLayout(new FlowLayout());
query2.add(new JLabel("Select PDB File:"));
query2.add(new JComboBox());
query3 = new JRadioButton();
query3.setLayout(new FlowLayout());
query3.add(new JLabel(" Enter Sequence :"));
query3.add(new JTextField(15));
target1 = new JRadioButton();
target1.setLayout(new FlowLayout());
target1.add(new JTextField(15));
target1.add(new JButton("Upload"));
target1.setSelected(true);
target2 = new JRadioButton();
target2.setLayout(new FlowLayout());
target2.add(new JLabel("Select PDB File :"));
target2.add(new JComboBox());
target3 = new JRadioButton();
target3.setLayout(new FlowLayout());
target3.add(new JLabel(" Enter Sequence :"));
target3.add(new JTextField(15));
//query group button
final ButtonGroup group1 = new ButtonGroup();
group1.add(query1);
group1.add(query2);
group1.add(query3);
//target group button
final ButtonGroup group2 = new ButtonGroup();
group2.add(target1);
group2.add(target2);
group2.add(target3);
JPanel querypane = new JPanel();
querypane.setLayout(new BoxLayout(querypane, BoxLayout.Y_AXIS));
querypane.setSize(10,10);
querypane.setBorder(BorderFactory.createTitledBorder("Query Structure"));
querypane.add(query1);
querypane.add(query2);
querypane.add(query3);
JPanel targetpane = new JPanel();
targetpane.setLayout(new BoxLayout(targetpane, BoxLayout.Y_AXIS));
targetpane.setSize(10,10);
targetpane.setBorder(BorderFactory.createTitledBorder("Target Structure"));
targetpane.add(target1);
targetpane.add(target2);
targetpane.add(target3);
//end of query & target layout
JCheckBox GeoHash, SuperPos, DynPro;
GeoHash = new JCheckBox();
GeoHash.setLayout(new FlowLayout());
GeoHash.add(new JLabel(" Geometric Hashing"));
GeoHash.add(new JButton("Results"));
//GeoHash.setLayout(new GridLayout(2,1) );
SuperPos = new JCheckBox();
SuperPos.setLayout(new FlowLayout());
SuperPos.add(new JLabel(" Superposition"));
SuperPos.add(new JButton("Results"));
DynPro = new JCheckBox();
DynPro.setLayout(new FlowLayout());
DynPro.add(new JLabel(" Dynamic Programming"));
DynPro.add(new JButton("Results"));
JPanel algorithmpane = new JPanel();
algorithmpane.setLayout(new BoxLayout(algorithmpane, BoxLayout.X_AXIS));
algorithmpane.setBorder(BorderFactory.createTitledBorder("Algorithms"));
algorithmpane.add(GeoHash);
algorithmpane.add(SuperPos);
algorithmpane.add(DynPro);
JTextArea screen = new JTextArea(20,60);
JPanel resultpane = new JPanel();
resultpane.setLayout(new FlowLayout());
resultpane.setLayout(new BoxLayout(resultpane, BoxLayout.X_AXIS));
resultpane.add(screen, BorderLayout.CENTER);
resultpane.setBorder(BorderFactory.createTitledBorder("Results"));
JButton Compute, Print, Save;
Compute = new JButton("Compute");
Compute.setLayout(new BoxLayout(Compute, BoxLayout.X_AXIS));
Print = new JButton("Print");
Print.setLayout(new BoxLayout(Print, BoxLayout.X_AXIS));
Save = new JButton("Save");
Save.setLayout(new BoxLayout(Save, BoxLayout.X_AXIS));
JPanel bottom = new JPanel();
bottom.setLayout(new FlowLayout());
//bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
bottom.add(Compute);
bottom.add(Print);
bottom.add(Save);
Container contentPane = getContentPane();
contentPane.add(querypane);
contentPane.add(targetpane);
contentPane.add(algorithmpane);
contentPane.add(resultpane);
contentPane.add(bottom);
}//end of Layout()
public static void main(String[] args) {
//create frame
Layout frame = new Layout() ;
frame.setResizable(false);
frame.setTitle("Biomolecular Structure Comparison");
frame.setSize(700,680);
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(100,0);
//show frame
frame.setVisible(true);
}//end of main
}//end of class