/****************************************************************/
/* MyForm */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
/**
* Summary description for MyForm
*
*/
public class MyForm extends JFrame
{
// Variables declaration
private JLabel jLabel1;
private JCheckBox btn_help;
private JList jList1;
private JScrollPane jScrollPane1;
private JButton btn_ok;
private JButton btn_cancel;
private JPanel contentPane;
//-----
private JCheckBox jCheckBox1;
private JCheckBox jCheckBox2;
private JPanel jPanel1;
//-----
private JRadioButton jRadioButton1;
private JRadioButton jRadioButton2;
private JPanel jPanel2;
//-----
private ButtonGroup btnGroup1;
// End of variables declaration
public MyForm()
{
super();
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
}
/**
* 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 Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
ArrayList arr;
jLabel1 = new JLabel();
btn_help = new JCheckBox();
jList1 = new JList();
jScrollPane1 = new JScrollPane();
btn_ok = new JButton();
btn_cancel = new JButton();
contentPane = (JPanel)this.getContentPane();
//-----
jCheckBox1 = new JCheckBox();
jCheckBox2 = new JCheckBox();
jPanel1 = new JPanel();
//-----
jRadioButton1 = new JRadioButton();
jRadioButton2 = new JRadioButton();
jPanel2 = new JPanel();
//-----
btnGroup1 = new ButtonGroup();
//
// jLabel1
//
jLabel1.setText("Words List:");
//
// btn_help
//
btn_help.setHorizontalAlignment(SwingConstants.CENTER);
btn_help.setIcon(new ImageIcon("C:\\Examples\\Query.png"));
btn_help.setOpaque(false);
btn_help.setToolTipText("Help");
btn_help.setSelected(true);
btn_help.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
btn_help_actionPerformed(e);
}
});
//
// jList1
//
arr = new ArrayList();
arr.add("Tech");
arr.add("Soft");
arr.add("Telecom");
arr.add("Solutions");
arr.add("Works");
arr.add("Dyne");
arr.add("Services");
arr.add("Vers");
arr.add("Devices");
arr.add("Dynamics");
arr.add("Net");
arr.add("System");
jList1.setListData(arr.toArray());
jList1.setSelectionBackground(new Color(162, 196, 136));
jList1.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e)
{
jList1_valueChanged(e);
}
});
//
// jScrollPane1
//
jScrollPane1.setViewportView(jList1);
//
// btn_ok
//
btn_ok.setOpaque(false);
btn_ok.setText("Ok");
btn_ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
btn_ok_actionPerformed(e);
}
});
//
// btn_cancel
//
btn_cancel.setOpaque(false);
btn_cancel.setText("Cancel");
btn_cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
btn_cancel_actionPerformed(e);
}
});
//
// contentPane
//
contentPane.setLayout(null);
contentPane.setBackground(new Color(187, 198, 161));
addComponent(contentPane, jLabel1, 20,11,84,18);
addComponent(contentPane, btn_help, 163,218,38,38);
addComponent(contentPane, jScrollPane1, 19,31,155,175);
addComponent(contentPane, btn_ok, 20,223,83,28);
addComponent(contentPane, btn_cancel, 256,223,83,28);
addComponent(contentPane, jPanel1, 187,22,155,88);
addComponent(contentPane, jPanel2, 187,120,155,88);
//
// jCheckBox1
//
jCheckBox1.setOpaque(false);
jCheckBox1.setText("One");
//
// jCheckBox2
//
jCheckBox2.setOpaque(false);
jCheckBox2.setText("Two");
//
// jPanel1
//
jPanel1.setLayout(new BoxLayout(jPanel1, BoxLayout.Y_AXIS));
jPanel1.add(jCheckBox1, 0);
jPanel1.add(jCheckBox2, 1);
jPanel1.setBorder(new TitledBorder("CheckBoxes"));
jPanel1.setBackground(new Color(187, 198, 161));
//
// jRadioButton1
//
jRadioButton1.setOpaque(false);
jRadioButton1.setText("Radio One");
jRadioButton1.setSelected(true);
//
// jRadioButton2
//
jRadioButton2.setOpaque(false);
jRadioButton2.setText("Radio Two");
//
// jPanel2
//
jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.Y_AXIS));
jPanel2.add(jRadioButton1, 0);
jPanel2.add(jRadioButton2, 1);
jPanel2.setBorder(new TitledBorder("Radio Buttons"));
jPanel2.setBackground(new Color(187, 198, 161));
//
// btnGroup1
//
btnGroup1.add(jRadioButton1);
btnGroup1.add(jRadioButton2);
//
// MyForm
//
this.setTitle("MyForm");
this.setLocation(new Point(1, 1));
this.setSize(new Dimension(364, 295));
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setResizable(false);
}
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void btn_help_actionPerformed(ActionEvent e)
{
System.out.println("\nbtn_help_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void jList1_valueChanged(ListSelectionEvent e)
{
System.out.println("\njList1_valueChanged(ListSelectionEvent e) called.");
if(!e.getValueIsAdjusting())
{
Object o = jList1.getSelectedValue();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
// TODO: Add any handling code here for the particular object being selected
}
}
private void btn_ok_actionPerformed(ActionEvent e)
{
System.out.println("\nbtn_ok_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void btn_cancel_actionPerformed(ActionEvent e)
{
System.out.println("\nbtn_cancel_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
//
// TODO: Add any method code to meet your needs in the following area
//
//============================= Testing ================================//
//= =//
//= The following main method is just for testing this class you built.=//
//= After testing,you may simply delete it. =//
//======================================================================//
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new MyForm();
}
//= End of Testing =
}
|
| __ |
|
|
|
Variables Declaration |
|
|
Constructor |
|
|
Variables Assignment |
|
|
Setting the properties for each component. |
|
|
Event Handling Methods have been done here.
Just need add a few statements into right methods.
|
|
|
User may add any particular methods to meet their
needs in this area. |
|
|
Main Method provided is just for testing this class.
|
|
|