of 36 /36
7/21/2019 Swing Prac http://slidepdf.com/reader/full/swing-prac 1/36 1: hello world: (label, button).  Take button and name is b1.  Take label and name it l1. In action performed event of button b1 write following: l1.setText(!"##$ %$&#')

Swing Prac

Embed Size (px)


java swings

Text of Swing Prac

1: hello world: (label, button).Take button and name is b1.Take label and name it l1.In action performed event of button b1 write following:l1.setText("HELLO WORLD");

2. greeting: (label, textfield, button).private void b1ActionPerformed(java.awt.event.ActionEvent evt) { String message = "hello "+t1.getText(); l2.setText(message); }

private void b2ActionPerformed(java.awt.event.ActionEvent evt) { t1.setText(""); l2.setText(""); }

3. login form: (label, textfield, passwordfiled, button, checkbox).private void b1ActionPerformed(java.awt.event.ActionEvent evt) { if(t1.getText().equalsIgnoreCase("abc") && t2.getText().equals("123")) { if(cb1.isSelected()==true) { l3.setText("login successfully"); } } else { l3.setText("login failed"); }


private void b2ActionPerformed(java.awt.event.ActionEvent evt) { t1.setText(""); t2.setText(""); l2.setText(""); cb1.setSelected(false); }

4. (label, scrollpane, textarea, radiobutton, button, buttongroup)Set editable property of textarea to false.Set enabled property of button to false.Goto events-window-windowOpen in vents of formCode:private void formWindowOpened(java.awt.event.WindowEvent evt) { bg1.add(rb1); bg1.add(rb2); }

private void rb1ActionPerformed(java.awt.event.ActionEvent evt) { b1.setEnabled(true); }

private void rb2ActionPerformed(java.awt.event.ActionEvent evt) { b1.setEnabled(false); }

5. label with image.Under default package- go to others- in that on left select others and in right select folder.Name the folder to images.Paste some images under images folder.Set the icon property of label.Code:import javax.swing.*; String[] imagenames = {"backdisc2.png","copydisc_cd.png","data_cd.png","video_cd.png"}; int count=0; private void b2ActionPerformed(java.awt.event.ActionEvent evt) { ImageIcon[] icon = new ImageIcon[4]; for(int i=0;i