Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts
Monday, 29 July 2013
/*
* login_form.java
*
* Created on July 16, 2013, 10:57 AM
*/
package loginform;
/**
*
* @author LTIET_CSE_DEPT
*/
public class login_form extends javax.swing.JFrame {
/** Creates new form login_form */
public login_form() {
initComponents();
jOptionPane1.setVisible(false);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
uname = new javax.swing.JTextField();
ok = new javax.swing.JButton();
cancel_btn = new javax.swing.JButton();
upass = new javax.swing.JPasswordField();
jOptionPane1 = new javax.swing.JOptionPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Name:");
jLabel2.setText("Password:");
ok.setText("OK");
ok.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okActionPerformed(evt);
}
});
cancel_btn.setText("Cancel");
cancel_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancel_btnActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(upass)
.addGroup(layout.createSequentialGroup()
.addComponent(ok)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancel_btn))
.addComponent(uname, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(84, 84, 84)
.addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(242, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(uname, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(upass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ok)
.addComponent(cancel_btn))
.addGap(28, 28, 28)
.addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(151, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
if(uname.getText().equals("Sagar"))
{
if(upass.getText().equals("123"))
{
jOptionPane1.showMessageDialog(this,"Welcome");
}
else{jOptionPane1.showMessageDialog(this,"Enter Correct Password");}
}
else{jOptionPane1.showMessageDialog(this,"Enter Correct UserName");}
}//GEN-LAST:event_okActionPerformed
private void cancel_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_btnActionPerformed
System.exit(0);
}//GEN-LAST:event_cancel_btnActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new login_form().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancel_btn;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JOptionPane jOptionPane1;
private javax.swing.JButton ok;
private javax.swing.JTextField uname;
private javax.swing.JPasswordField upass;
// End of variables declaration//GEN-END:variables
}
* login_form.java
*
* Created on July 16, 2013, 10:57 AM
*/
package loginform;
/**
*
* @author LTIET_CSE_DEPT
*/
public class login_form extends javax.swing.JFrame {
/** Creates new form login_form */
public login_form() {
initComponents();
jOptionPane1.setVisible(false);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
uname = new javax.swing.JTextField();
ok = new javax.swing.JButton();
cancel_btn = new javax.swing.JButton();
upass = new javax.swing.JPasswordField();
jOptionPane1 = new javax.swing.JOptionPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Name:");
jLabel2.setText("Password:");
ok.setText("OK");
ok.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okActionPerformed(evt);
}
});
cancel_btn.setText("Cancel");
cancel_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancel_btnActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(upass)
.addGroup(layout.createSequentialGroup()
.addComponent(ok)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancel_btn))
.addComponent(uname, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(84, 84, 84)
.addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(242, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(uname, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(upass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ok)
.addComponent(cancel_btn))
.addGap(28, 28, 28)
.addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(151, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
if(uname.getText().equals("Sagar"))
{
if(upass.getText().equals("123"))
{
jOptionPane1.showMessageDialog(this,"Welcome");
}
else{jOptionPane1.showMessageDialog(this,"Enter Correct Password");}
}
else{jOptionPane1.showMessageDialog(this,"Enter Correct UserName");}
}//GEN-LAST:event_okActionPerformed
private void cancel_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_btnActionPerformed
System.exit(0);
}//GEN-LAST:event_cancel_btnActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new login_form().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancel_btn;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JOptionPane jOptionPane1;
private javax.swing.JButton ok;
private javax.swing.JTextField uname;
private javax.swing.JPasswordField upass;
// End of variables declaration//GEN-END:variables
}
Saturday, 27 July 2013
package ajt;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class StudentReg extends JPanel implements ActionListener {
JButton b1;
JTextField t1,t2,t3;
JLabel l1,l2,l3,l4;
JCheckBox c1,c2,c3;
JRadioButton r1,r2;
ButtonGroup bg1;
JComboBox cb;
String str="Game : ";
JCheckBox c[] = new JCheckBox[3];
public StudentReg()
{
b1 = new JButton("Submit");
t1 = new JTextField("Sagar",10);
t2 = new JTextField("CE",10);
t3 = new JTextField("Botad",10);
l1 = new JLabel("Name");
l2 = new JLabel("Branch");
l3 = new JLabel("Address");
l4 = new JLabel("Car");
r1 = new JRadioButton("Male");
r1.setActionCommand("male");
r2 = new JRadioButton("Female");
r2.setActionCommand("female");
c1 = new JCheckBox("Cricket");
c2 = new JCheckBox("FootBall");
c3 = new JCheckBox("VollyBall");
cb = new JComboBox();
bg1 = new ButtonGroup();
cb.addItem("BMW");
cb.addItem("AUDI");
cb.addItem("AMW");
b1.addActionListener(this);
bg1.add(r1);
bg1.add(r2);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(cb);
add(r1);add(r2);
add(c1);add(c2);add(c3);
add(b1);
}
public void actionPerformed(ActionEvent e)
{
String name = t1.getText();
System.out.println("Name : "+name);
String branch = t2.getText();
System.out.println("Branch : "+branch);
String add = t3.getText();
System.out.println("Address : "+add);
String car = cb.getSelectedItem().toString();
System.out.println("Car : "+car);
if(bg1.getSelection().getActionCommand().equals("male"))
{
System.out.println("Gender : Male");
}
else
{
System.out.println("Gender : Female");
}
if(c1.isSelected())
{
str = str +"Cricket ";
}
if(c2.isSelected())
{
str = str+"+ FootBall";
}
if(c3.isSelected())
{
str = str+ "+ VollyBall ";
}
System.out.println(" "+str);
}
public static void main(String args[])
{
JFrame frame = new JFrame("JButtonDemo");
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.getContentPane().add(new StudentReg());
frame.pack();
frame.setVisible(true);
}
}
package ajt;
/**
*
* @author SAGAR
*/
public class StudentRegForm extends javax.swing.JFrame {
/** Creates new form StudentRegForm */
public StudentRegForm() {
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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jCheckBox1 = new javax.swing.JCheckBox();
jCheckBox2 = new javax.swing.JCheckBox();
jCheckBox3 = new javax.swing.JCheckBox();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Name");
jLabel2.setText("Branch");
jLabel3.setText("Address");
jRadioButton1.setText("Male");
jRadioButton2.setText("Female");
jTextField1.setToolTipText("");
jLabel4.setText("State");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cars", "Bike", "Bicycle" }));
jComboBox1.setToolTipText("");
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jCheckBox1.setText("Cricket");
jCheckBox2.setText("FootBall");
jCheckBox3.setText("VollyBall");
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"
}
));
jScrollPane1.setViewportView(jTable1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE))
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextField2)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jCheckBox3)
.addComponent(jCheckBox2)
.addComponent(jCheckBox1)))
.addComponent(jButton1)))
.addComponent(jRadioButton2)
.addComponent(jRadioButton1))
.addContainerGap(344, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2))
.addGroup(layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(jCheckBox1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jCheckBox2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jCheckBox3)))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(79, 79, 79))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String name = jTextField1.getText();
System.out.println("Name : " + name);
String branch = jTextField2.getText();
System.out.println("Branch : " + branch);
String address = jTextField3.getText();
System.out.println("Address : " + address);
String s = jComboBox1.getSelectedItem().toString();
System.out.println("State : "+ s);
jCheckBox1.getSelectedObjects().toString();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new StudentRegForm().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton jButton1;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JCheckBox jCheckBox3;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
}
- import javax.swing.JFrame;
- import javax.swing.JCheckBox;
- import javax.swing.JButton;
- import javax.swing.JOptionPane;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class GetSelectedJCheckBox implements ActionListener
- {
- //Create String that will be use to hold selected JCheckBox text
- String selectedCheckBox="";
- //Create check box using JCheckBox
- JCheckBox checkBox1=new JCheckBox("Duck");
- JCheckBox checkBox2=new JCheckBox("Chicken");
- JCheckBox checkBox3=new JCheckBox("Cow");
- JCheckBox checkBox4=new JCheckBox("Sheep");
- //Create button using JButton with text ( Get selected JCheckBox )
- JButton button=new JButton("Get selected JCheckBox");
- //method actionPerformed that we override because we implement ActionListener
- public void actionPerformed(ActionEvent event)
- {
- //Action for button
- if(event.getSource()==button)
- {
- //Check first JCheckBox is selected or not
- if(checkBox1.isSelected())
- {
- selectedCheckBox=selectedCheckBox+checkBox1.getText()+"\n";
- }
- //Check second JCheckBox is selected or not
- if(checkBox2.isSelected())
- {
- selectedCheckBox=selectedCheckBox+checkBox2.getText()+"\n";
- }
- //Check third JCheckBox is selected or not
- if(checkBox3.isSelected())
- {
- selectedCheckBox=selectedCheckBox+checkBox3.getText()+"\n";
- }
- //Check fourth JCheckBox is selected or not
- if(checkBox4.isSelected())
- {
- selectedCheckBox=selectedCheckBox+checkBox4.getText()+"\n";
- }
- //Show message that tell you, what check box that you selected
- JOptionPane.showMessageDialog(null,"Selected check box is : \n"+selectedCheckBox);
- //Make selectedCheckBox string like initial with empty string
- selectedCheckBox=new String("");
- }
- }
- //Constructor
- public GetSelectedJCheckBox()
- {
- //Create a window using JFrame with title ( Get selected JCheckBox )
- JFrame frame=new JFrame("Get selected JCheckBox");
- //Create layout that will be use by JFrame
- GridLayout gl=new GridLayout(5,1);
- //Add ActionListener to button
- button.addActionListener(this);
- //Set JFrame layout
- frame.setLayout(gl);
- //Add all created check box into JFrame
- frame.add(checkBox1);
- frame.add(checkBox2);
- frame.add(checkBox3);
- frame.add(checkBox4);
- //Add created button into JFrame
- frame.add(button);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(350,200);
- frame.setVisible(true);
- }
- //Main method
- public static void main(String[]args)
- {
- GetSelectedJCheckBox gsjcb=new GetSelectedJCheckBox();
- }
- }
Subscribe to:
Posts (Atom)
Blogger templates
Popular Posts
-
500 topics for projects. IT engineering Final year projects and mini projects,Computer Science & Engineering final year project idea Hi ...
-
If you want to block tough proxies like hidemyass.com, my previously posted .htaccess methods won’t work. Those methods will block quite...
-
There are many ways to encode and decode PHP code. From the perspective of site security, there are three PHP functions — str_rot13() , b...
-
By Noura Yehia JavaScript libraries have made huge leaps and bounds in helping developers write code and develop products more quickly. jQu...
-
There are a number of tricks that can make your life easier and help you to squeeze the last bit of performance from your scripts. These t...
-
Ajax-Powered Error Logs Update: Check out the new and improved Ajax Error Log Version 2.0! As an obsessive website administrator, I like to...
-
60+ Awesome New WordPress Themes Blog Post In: http://www.webdesignerdepot.com It seems like every time you go looking for a new WordPress ...
-
Create your own API with Restler By Richard Askew on July 17, 2013 | 1 comment ...
-
Enterprise Resource Planning Tutorial : Download Here
-
PHP Tip: Encode & Decode Data URLs Converting small images to data-URLs is a great way to eliminate HTTP requests and decrease loading...
Recent Posts
Unordered List
Blog Archive
-
▼
2013
(47)
-
▼
September
(9)
- Enterprise Resource Planning Tutorial
- Encoding & Decoding PHP Code
- Block Tough Proxies
- Web Developing - Computer Engineering: 60+ Awesome...
- How to upload large file using php or code of uplo...
- Computer Engineering: HTTP Headers for ZIP File Do...
- Ajax-Powered Error Logs
- Computer Engineering: Ajax-Powered Error Logs
- Computer Engineering: Display Latest Tweet with Sh...
-
▼
September
(9)



