Class 1, Part 2 | Intro to Java 30-IT-396 |
Comprehensive Swing Example
/*
* SwingExamples.java
*
* Created on February 27, 2002, 12:26 AM
*/
/**
*
* @author default
*/
public class SwingExamples extends javax.swing.JFrame {
String strCopy;
boolean blnCheckBox = false;
/** Creates new form SwingExamples */
public SwingExamples() {
initComponents();
}
/** 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.
*/
private void initComponents() {//GEN-BEGIN:initComponents
grpSelection = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
btnCopy = new javax.swing.JButton();
btnPaste = new javax.swing.JButton();
btnAdd = new javax.swing.JButton();
ckbList = new javax.swing.JCheckBox();
pnlContent = new javax.swing.JPanel();
txtUserText = new javax.swing.JTextField();
cmbEnteredOptions =
new javax.swing.JComboBox();
txtPastedData = new
javax.swing.JTextArea();
pnlTopPanel = new javax.swing.JPanel();
rdoEnter = new javax.swing.JRadioButton();
rdoExit = new javax.swing.JRadioButton();
lblGreet = new javax.swing.JLabel();
addWindowListener(new
java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
btnCopy.setText("Copy");
btnCopy.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCopyActionPerformed(evt);
}
});
jPanel1.add(btnCopy);
btnPaste.setText("Paste");
btnPaste.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPasteActionPerformed(evt);
}
});
jPanel1.add(btnPaste);
btnAdd.setText("Add");
btnAdd.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAddActionPerformed(evt);
}
});
jPanel1.add(btnAdd);
ckbList.setText("From
List");
ckbList.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ckbListActionPerformed(evt);
}
});
jPanel1.add(ckbList);
getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
txtUserText.setColumns(20);
pnlContent.add(txtUserText);
pnlContent.add(cmbEnteredOptions);
txtPastedData.setColumns(20);
txtPastedData.setRows(4);
pnlContent.add(txtPastedData);
getContentPane().add(pnlContent, java.awt.BorderLayout.CENTER);
rdoEnter.setText("Entering");
grpSelection.add(rdoEnter);
rdoEnter.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rdoEnterActionPerformed(evt);
}
});
pnlTopPanel.add(rdoEnter);
rdoExit.setText("Leaving");
grpSelection.add(rdoExit);
rdoExit.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rdoExitActionPerformed(evt);
}
});
pnlTopPanel.add(rdoExit);
lblGreet.setBorder(new
javax.swing.border.EtchedBorder());
pnlTopPanel.add(lblGreet);
getContentPane().add(pnlTopPanel, java.awt.BorderLayout.NORTH);
pack();
}//GEN-END:initComponents
private void ckbListActionPerformed(java.awt.event.ActionEvent
evt) {//GEN-FIRST:event_ckbListActionPerformed
// Add your handling
code here:
}//GEN-LAST:event_ckbListActionPerformed
private void rdoEnterActionPerformed(java.awt.event.ActionEvent
evt) {//GEN-FIRST:event_rdoEnterActionPerformed
// Add your handling
code here:
lblGreet.setText("Hello!");
}//GEN-LAST:event_rdoEnterActionPerformed
private void rdoExitActionPerformed(java.awt.event.ActionEvent
evt) {//GEN-FIRST:event_rdoExitActionPerformed
// Add your handling
code here:
lblGreet.setText("Goodbye!");
}//GEN-LAST:event_rdoExitActionPerformed
private void btnAddActionPerformed(java.awt.event.ActionEvent
evt) {//GEN-FIRST:event_btnAddActionPerformed
// Add your handling
code here:
cmbEnteredOptions.addItem(txtUserText.getText());
}//GEN-LAST:event_btnAddActionPerformed
private void btnPasteActionPerformed(java.awt.event.ActionEvent
evt) {//GEN-FIRST:event_btnPasteActionPerformed
// Add your handling
code here:
txtPastedData.setText(txtPastedData.getText()
+ strCopy);
}//GEN-LAST:event_btnPasteActionPerformed
private void btnCopyActionPerformed(java.awt.event.ActionEvent
evt) {//GEN-FIRST:event_btnCopyActionPerformed
// Add your handling
code here:
if (blnCheckBox) {
strCopy = (String) this.ckbList.getSelectedObjects()[0];
// strCopy = (String) ckbList.getSelectedItem();
} else {
strCopy = txtUserText.getText();
}
}//GEN-LAST:event_btnCopyActionPerformed
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent
evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new SwingExamples().show();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField txtUserText;
private javax.swing.JComboBox cmbEnteredOptions;
private javax.swing.ButtonGroup grpSelection;
private javax.swing.JRadioButton rdoExit;
private javax.swing.JPanel pnlTopPanel;
private javax.swing.JTextArea txtPastedData;
private javax.swing.JCheckBox ckbList;
private javax.swing.JButton btnAdd;
private javax.swing.JButton btnPaste;
private javax.swing.JPanel pnlContent;
private javax.swing.JButton btnCopy;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lblGreet;
private javax.swing.JRadioButton rdoEnter;
// End of variables declaration//GEN-END:variables
}
Created by: Brandan
Jones January 4, 2002