1.
program on bu on component
import java.awt.*;
import java.awt.event.*;
class ColorsFrame extends Frame implements Ac onListener
Bu on bl, b2, b3;
ColorsFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle( "Colors Frame ");
this.setLayout(new FlowLayout());
this.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent we)
System.exit(0);
});
bl=new Bu on("Red");
b2=new Bu on("Green");
b3=new Bu on("Blue");
bl.addAc onListener(this);
b2.addAc onListener(this);
b3.addAc onListener(this);
bl.setBackground(Color.red);
b2.setBackground(Color.green);
b3.setBackground(Color.blue);
this.add(bl);
this.add(b2);
this.add(b3);
public void ac onPerformed(Ac onEvent ae)
String label=ae.getAc onCommand();
if(label.equals("Red"))
this.setBackground(Color.red);
if(label.equals("Green"))
this.setBackground(Color.green);
if(label.equals("Blue"))
this.setBackground(Color.blue);
class Bu onEx
public sta c void main(String[] args)
ColorsFrame cf=new ColorsFrame();
2. programs on text field and textarea.
import java.awt.*;
import java.awt.event.*;
class UserFrame extends Frame implements Ac onListener{
Label l1, l2, l3, l4, l5;
TextField l, 2, 3, 4;
TextArea ta;
Bu on b;
String uname = " ";
String upwd = " ";
String uemail = " ";
String umobile = " ";
String uaddr = " ";
UserFrame() {
this.setVisible(true);
this.setSize(1000, 1000);
this.setTitle("User Frame");
this.setBackground(Color.green);
this.setLayout(new FlowLayout());
// Adding components to the frame
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
});
l1 = new Label("User Name");
l2 = new Label("Password");
l3 = new Label("User Email");
l4 = new Label("User Mobile");
l5 = new Label("User Address");
l = new TextField(20);
2 = new TextField(20);
2.setEchoChar('*');
3 = new TextField(20);
4 = new TextField(20);
ta = new TextArea(3, 15);
b = new Bu on("Registra on");
b.addAc onListener(this);
Font f = new Font("arial", Font.BOLD, 15);
l1.setFont(f);
l2.setFont(f);
l3.setFont(f);
l4.setFont(f);
l5.setFont(f);
l.setFont(f);
2.setFont(f);
3.setFont(f);
4.setFont(f);
ta.setFont(f);
b.setFont(f);
this.add(l1);this.add( l);
this.add(l2);this.add( 2);
this.add(l3);this.add( 3);
this.add(l4);this.add( 4);
this.add(l5);this.add(ta);
this.add(b);
public void ac onPerformed(Ac onEvent ae) {
uname = l.getText();
upwd = 2.getText();
uemail = 3.getText();
umobile = 4.getText();
uaddr = ta.getText();
repaint();
public void paint(Graphics g) {
Font f = new Font("arial", Font.BOLD, 20);
g.setFont(f);
g.drawString("User Name :" + uname, 50, 250);
g.drawString("Password :" + upwd, 50, 300);
g.drawString("User Email :" + uemail, 50, 350);
g.drawString("User Mobile :" + umobile, 50, 400);
g.drawString("User Address :" + uaddr, 50, 450);
public class TextFieldEx
public sta c void main(String[] args)
UserFrame uf=new UserFrame();
}}
3.program on checkbox and radio bu on
import java.awt.*;
import java.awt.event.*;
class UserFrame extends Frame implements ItemListener
Label l1, l2;
Checkbox cb1, cb2, cb3, cb4, cb5;
String uqual=" ";
String ugender= " ";
UserFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("Check Box Example");
this.setBackground(Color.green);
this.setLayout(new FlowLayout());
this.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent we)
System.exit(0);
});
l1=new Label(" User Qualifica ons");
l2=new Label("User Gender");
cb1=new Checkbox( "BSC",null, false);
cb2=new Checkbox("MCA" ,null, false);
cb3=new Checkbox("phd",null, false);
CheckboxGroup cg=new CheckboxGroup();
cb4=new Checkbox("Male",cg, false);
cb5=new Checkbox("Female",cg, false);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
cb4.addItemListener(this);
cb5.addItemListener(this);
Font f=new Font("arial", Font.BOLD, 15);
l1.setFont(f);
l2.setFont(f);
cb1.setFont(f);
cb2.setFont(f);
cb3.setFont(f);
cb4.setFont(f);
cb5.setFont(f);
this.add(l1);
this.add(cb1);
this.add(cb2);
this.add(cb3);
this.add(l2);
this.add(cb4);
this.add(cb5);
public void itemStateChanged(ItemEvent ie)
if(cb1.getState() == true)
uqual=uqual+cb1.getLabel()+" ";
}
if(cb2.getState()==true)
uqual=uqual+cb2.getLabel()+" ";
if(cb3.getState() == true)
uqual=uqual+cb3.getLabel()+" ";
if(cb4.getState()==true)
ugender=cb4.getLabel();
if(cb5.getState() == true)
ugender=cb5.getLabel();
repaint();
public void paint(Graphics g)
Font f=new Font("arial",Font.BOLD, 30);
g.setFont(f);
g.drawString("QuaIifica ons :"+uqual, 50, 300);
g.drawString("Gender :"+ugender, 50, 350);
uqual="";
public class CheckBoxEx
{
public sta c void main(String[] args)
UserFrame uf=new UserFrame();
4.program on list and choice.
import java.awt.*;
import java.awt.event.*;
class UserFrame extends Frame implements ItemListener
Label l1,l2;
List l;
Choice ch;
String utech="";
String uprof="";
UserFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("List Example");
this.setBackground(Color.green);
this.setLayout(new FlowLayout());
this.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent we)
System.exit(0);
});
l1=new Label(" User Technologies");
l2=new Label("User Profession");
l=new List(4,true);
l.add("C");
l.add("C++");
l.add("java");
l.add("python");
l.add("oracle");
l.addItemListener(this);
ch=new Choice();
ch.add("Student");
ch.add("EmpIoyee");
ch.add("Teacher");
ch.addItemListener(this);
this.add(l1); this.add(l);
this.add(l2); this.add(ch);
public void itemStateChanged(ItemEvent ie)
String[] items=l.getSelectedItems();
for(int i=0;i<items.length;i++)
utech=utech+items[i]+" ";
uprof=ch.getSelectedItem();
repaint();
public void paint(Graphics g)
Font f=new Font("arial",Font.BOLD, 30);
g.setFont(f);
g.drawString("Technologies :"+utech, 50, 300);
g.drawString("Profession :"+uprof, 50, 350);
utech="";
class ListEx
public sta c void main(String[] args)
UserFrame uf=new UserFrame();
5.programs menu bar,menu and menu item
import java.awt.*;
import java.awt.event.*;
class UserFrame extends Frame implements Ac onListener
MenuBar mb;
Menu m;
MenuItem mi1, mi2, mi3;
String item="";
UserFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("Menu Example");
this.setBackground(Color.green);
this.setLayout(new FlowLayout());
this.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent we)
{
System.exit(0);
});
mb=new MenuBar();
this.setMenuBar(mb);
m=new Menu("File");
mb.add(m);
mi1=new MenuItem("new");
mi2=new MenuItem("Open");
mi3=new MenuItem("Save");
m.add(mi1);
m.add(mi2);
m.add(mi3);
mi1.addAc onListener(this);
mi2.addAc onListener(this);
mi3.addAc onListener(this);
public void ac onPerformed(Ac onEvent ae)
item=ae.getAc onCommand();
repaint();
public void paint(Graphics g)
Font f=new Font("arial",Font.BOLD,30);
g.setFont(f);
g.drawString("Selected Item :"+item, 50, 300);
}
class MenuEx
public sta c void main(String[] args)
UserFrame uf=new UserFrame();
6.program on scrollbar
import java.awt.*;
import java.awt.event.*;
class UserFrame extends Frame implements AdjustmentListener
Scrollbar sb;
int posi on;
UserFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("scrollbar Example");
this.setBackground(Color.green);
this.setLayout(new BorderLayout());
this.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent we)
System.exit(0);
});
sb=new Scrollbar(Scrollbar.VERTICAL);
sb.addAdjustmentListener(this);
this.add(BorderLayout.EAST,sb);
public void adjustmentValueChanged(AdjustmentEvent ae)
posi on=sb.getValue();
repaint();
public void paint(Graphics g)
Font f=new Font("arial", Font.BOLD, 30);
g.setFont(f);
g.drawString("Posi on :"+posi on, 50, 300);
class ScrollBarEx
public sta c void main(String[] args)
UserFrame uf=new UserFrame();
7.paint method in frame
import java.awt.*;
class MyFrame extends Frame
MyFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("user defined frame");
this.setBackground(Color.GREEN);
}
//with out calling paint method how the effects shown to gui?
//in constructors before execu ng subclass , super class
//constructor is executed . Frame is super class.
//in Frame class there is a method called repaint() it calls , update(Graphics g)
// then it calss paint(Graphics g)
public void paint(Graphics g)
Font f= new Font("arial" , Font.ITALIC+Font.BOLD,35);
this.setForeground(Color.RED);
g.setFont(f);
g.drawString("gui frame" , 100,100);
class MyFrame1
public sta c void main(String[] args)
MyFrame mf= new MyFrame();
8.grid layout
import java.awt.*;
public class GridLayout1 extends Frame
public GridLayout1()
// Create Bu ons
Bu on bu on1 = new Bu on("Bu on 1");
Bu on bu on2 = new Bu on("Bu on 2");
Bu on bu on3 = new Bu on("Bu on 3");
Bu on bu on4 = new Bu on("Bu on 4");
Bu on bu on5 = new Bu on("Bu on 5");
// Set layout manager to GridLayout
setLayout(new GridLayout(2, 3)); // 2 rows, 3 columns
// Add bu ons to the frame
add(bu on1);
add(bu on2);
add(bu on3);
add(bu on4);
add(bu on5);
// Se ng frame proper es
setSize(300, 200);
setTitle("GridLayout Example");
setVisible(true);
// Handle window close event
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
System.exit(0);
});
public sta c void main(String[] args) {
new GridLayout1();
}
9.program on keyboard event
import java.awt.*;
import java.awt.event.*;
class KeyListenerImpl implements KeyListener
public void keyPressed(KeyEvent ke)
System.out.println("KeyPressed["+ke.getKeyChar()+"]");
public void keyTyped(KeyEvent ke)
System.out.println("KeyTyped["+ke.getKeyChar()+"]");
public void keyReleased(KeyEvent ke)
System.out.println("KeyReleased["+ke.getKeyChar()+"]");
class MyFrame extends Frame
MyFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("Window Events Example");
this.setBackground(Color.green);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
System.out.println("WindowClosing");
System.exit(0);
});
this.addKeyListener(new KeyListenerImpl());
class KeyEventsEx
public sta c void main(String[] args)
MyFrame mf=new MyFrame();
9b. keyboard event handling abstract adaptor class methods
import java.awt.*;
import java.awt.event.*;
class KeyAdapter implements KeyListener
public void keyPressed(KeyEvent ke)
public void keyTyped(KeyEvent ke)
public void keyReleased(KeyEvent ke)
}
10.program on mousevent
import java.awt.*;
import java.awt.event.*;
class MouseListenerImpl implements MouseListener
public void mousePressed(MouseEvent me)
System.out.println("Mouse Pressed["+me.getX()+","+me.getY()+"]");
public void mouseReleased(MouseEvent me)
System.out.println("Mouse Released["+me.getX()+","+me.getY()+"]");
public void mouseClicked(MouseEvent me)
System.out.println("Mouse Clicked["+me.getX()+","+me.getY()+"]");
public void mouseEntered(MouseEvent me)
System.out.println("Mouse Entered["+me.getX()+","+me.getY()+"]");
public void mouseExited(MouseEvent me)
System.out.println("Mouse Exited["+me.getX()+","+me.getY()+"]");
class MyFrame extends Frame
MyFrame()
{
this.setVisible(true);
this.setSize(500,500);
this.setTitle("Window Events Example");
this.setBackground(Color.green);
this.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent we)
System.out.println("WindowClosing");
System.exit(0);
});
this.addMouseListener(new MouseListenerImpl());
class MouseEventEx
public sta c void main(String[] args)
MyFrame mf=new MyFrame();
10b.mouse event handling abstract adopter class methods
import java.awt.*;
import java.awt.event.*;
class MouseAdapter implements MouseListener
public void mousePressed(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
public void mouseClicked(MouseEvent me)
public void mouseEntered(MouseEvent me)
public void mouseExited(MouseEvent me)
11.customclass with extends frame class for customiza on in frame
import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame
MyFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("Window Events Example");
this.setBackground(Color.green);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
System.out.println("WindowClosing");
System.exit(0);
});
class WindowEventex
public sta c void main(String[] args)
MyFrame mf=new MyFrame();
12.program on windowevent
import java.awt.*;
import java.awt.event.*;
class WindowListenerImpl implements WindowListener
public void windowOpened(WindowEvent we)
System.out.println("WindowOpened");
public void windowClosed(WindowEvent we)
System.out.println("WidnowClosed");
public void windowClosing(WindowEvent we)
{
System.out.println("WidnowClosing");
System.exit(0);
public void windowIconified(WindowEvent we)
System.out.println("Widnowlconified");
public void windowDeiconified(WindowEvent we)
System.out.println("windowDeiconified");
public void windowAc vated(WindowEvent we)
System.out.println("WindowAc vated");
public void windowDeac vated(WindowEvent we)
System.out.println("WindowDeac vated");
class MyFrame extends Frame
MyFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("Window Events Example");
this.setBackground(Color.green);
this.addWindowListener(new WindowListenerImpl());
}
class WindowEventsEx
public sta c void main(String[] args)
MyFrame mf=new MyFrame();
12b) window event handling abstract adopter class methods
Class WindowAdapter implements WindowListener
public void windowOpened(WindowEvent we)
public void windowClosed(WindowEvent we)
public void windowClosing(WindowEvent we)
public void windowIconified(WindowEvent we)
public void windowDeiconified(WindowEvent we)
}
public void windowAc vated(WindowEvent we)
public void windowDeac vated(WindowEvent we)
13.program to create simple frame without extending.
import java.awt.*;
class Frame1
public sta c void main(String[] args)
Frame f = new Frame("csmb");
//f.show();
f.setVisible(true);
f.setSize(500,500);
f.setTitle("csmb");
f.setBackground(Color.RED);
14.program on textarea with listener methods
import java.awt.*;
import java.awt.event.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
public class TextArea1 extends Frame
private TextArea textArea;
public TextArea1() {
// Create TextArea
textArea = new TextArea();
// Adding FocusListener to the TextArea
textArea.addFocusListener(new FocusListener()
public void focusGained(FocusEvent e)
System.out.println("Focus gained on the TextArea");
public void focusLost(FocusEvent e)
System.out.println("Focus lost on the TextArea");
});
add(textArea);
setSize(300, 200);
setTitle("TextArea Focus Example");
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
System.out.println("Window closing");
dispose();
System.exit(0);
);
public sta c void main(String[] args) {
new TextArea1();
15.program on Dialogbox
import javax.swing.JBu on;
import javax.swing.JFrame;
import javax.swing.JOp onPane;
import javax.swing.JPanel;
import java.awt.event.Ac onEvent;
import java.awt.event.Ac onListener;
public class CustomDialog extends JFrame {
public CustomDialog() {
setTitle("Main Frame");
setSize(400, 300);
setDefaultCloseOpera on(JFrame.EXIT_ON_CLOSE);
JBu on showDialogBu on = new JBu on("Show Dialog");
showDialogBu on.addAc onListener(new Ac onListener() {
public void ac onPerformed(Ac onEvent e) {
showDialog();
});
JPanel panel = new JPanel();
panel.add(showDialogBu on);
add(panel);
private void showDialog() {
JOp onPane.showMessageDialog(this, "Hello, this is a simple JOp onPane dialog!",
"Informa on", JOp onPane.INFORMATION_MESSAGE);
//JOp onPane.INFORMATION_MESSAGE: This parameter specifies
the type of icon that will be
//displayed in the dialog box. INFORMATION_MESSAGE indicates
that an informa on icon will
//be displayed. Other possible values include ERROR_MESSAGE,
WARNING_MESSAGE,
//QUESTION_MESSAGE, and PLAIN_MESSAGE.
public sta c void main(String[] args) {
CustomDialog customDialog = new CustomDialog();
customDialog.setVisible(true);
16.program on Jsplitpane
import javax.swing.*;
import java.awt.*;
public class SplitPaneExample extends JFrame {
public SplitPaneExample() {
setTitle("Split Pane Example");
setSize(400, 300);
setDefaultCloseOpera on(JFrame.EXIT_ON_CLOSE);
// Create two panels
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
// Add some components to each panel
panel1.add(new JLabel("Le Panel Content"));
panel2.add(new JLabel("Right Panel Content"));
// Create a split pane with the two panels
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, panel2);
// Set the ini al divider loca on (op onal)
splitPane.setDividerLoca on(200);
// Add the split pane to the frame
getContentPane().add(splitPane);
// Set the frame to be visible
setVisible(true);
public sta c void main(String[] args) {
new SplitPaneExample();
}
}
17.program on Jtabbedpane
import javax.swing.*;
import java.awt.*;
public class TabbedPaneExample extends JFrame {
public TabbedPaneExample() {
setTitle("Tabbed Pane Example");
setDefaultCloseOpera on(JFrame.EXIT_ON_CLOSE);
setSize(400, 300);
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panel1 = new JPanel();
panel1.add(new JLabel("Content for Tab 1"));
tabbedPane.addTab("Tab 1", null, panel1, "Tab 1 Tool p");
JPanel panel2 = new JPanel();
panel2.add(new JLabel("Content for Tab 2"));
tabbedPane.addTab("Tab 2", null, panel2, "Tab 2 Tool p");
JPanel panel3 = new JPanel();
panel3.add(new JLabel("Content for Tab 3"));
tabbedPane.addTab("Tab 3", null, panel3, "Tab 3 Tool p");
getContentPane().add(tabbedPane);
// Set the frame to be visible
setVisible(true);
}
public sta c void main(String[] args) {
new TabbedPaneExample();
18.program on JScrollPane
import javax.swing.*;
public class ScrollPaneExample extends JFrame {
public ScrollPaneExample() {
setTitle("Ver cal Scroll Pane Example");
setSize(300, 200);
setDefaultCloseOpera on(JFrame.EXIT_ON_CLOSE);
// Create a JTextArea with some text
JTextArea textArea = new JTextArea("This is a JTextArea inside a ver cal JScrollPane.\n"
+ "You can use JScrollPane to provide ver cal scrolling func onality.");
// Create a JScrollPane with ver cal scrolling and add the JTextArea to it
JScrollPane scrollPane = new JScrollPane(textArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// Set up the layout
getContentPane().add(scrollPane);
// Set the frame to be visible
setVisible(true);
public sta c void main(String[] args) {
new ScrollPaneExample();
19.program on JFileChooser
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
class FileChooserFrame extends JFrame implements Ac onListener
JLabel l;
TextField ;
JBu on b;
Container c;
JFileChooser fc;
FileChooserFrame()
this.setVisible(true);
this.setSize(500,500);
this.setTitle("File Chooser Example");
this.setDefaultCloseOpera on(JFrame.EXIT_ON_CLOSE);
c=this.getContentPane();
c.setBackground(Color.pink);
c.setLayout(new FlowLayout());
l=new JLabel("Select File");
=new TextField (20);
b=new JBu on("Browse");
b.addAc onListener(this);
c.add(l);c.add( );c.add(b);
}
public void ac onPerformed(Ac onEvent ae)
class FileDialogFrame extends JFrame implements Ac onListener
FileDialogFrame()
this.setVisible(true);
this.setSize(500,500);
fc=new JFileChooser();
fc.addAc onListener(this);
this.getContentPane().add(fc);
public void ac onPerformed(Ac onEvent ae)
File f=fc.getSelectedFile();
String path=f.getAbsolutePath();
.setText(path);
this.setVisible(false);
FileDialogFrame ff=new FileDialogFrame();
class FileChooserEx
public sta c void main(String[] args)
FileChooserFrame f=new FileChooserFrame();
}
}
20.program on JTable
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
class TableEx
public sta c void main(String[] args)
String[] header={"EID", "ENAME", "ESAL", "EADDR"};
Object[][] body={{"e1","AAA","5000", "Hyderabad"},{" e2" , "BBB", "6000",
"Secbad"},{"e3", "CCC", "7000", "Vijayawada"},{"e4", "DDD", "8000", "Warngal"}};
JFrame f=new JFrame();
f.setVisible(true);
f.setSize(500,500);
Container c=f.getContentPane();
c.setLayout(new BorderLayout());
JTable t=new JTable(body,header);
JTableHeader th=t.getTableHeader();
c.add(th,BorderLayout.NORTH);
c.add(t,BorderLayout.CENTER);
21.registra on applica on by using swing component
import javax.swing.*;
import java.awt.*;
import java.awt.event.Ac onEvent;
import java.awt.event.Ac onListener;
import java.u l.List;
class Registra onFrame extends JFrame implements Ac onListener {
JLabel l1, l2, l3, l4, l5, l6, l7;
JTextField ;
JPasswordField pf;
JCheckBox cb1, cb2, cb3;
JRadioBu on rb1, rb2;
JList<String> l;
JComboBox<String> cb;
JTextArea ta;
JBu on b;
Container c;
String uname = "", upwd = "", uqual = "", ugen = "", uprof = "", uaddr = "";
String[] utech;
Registra onFrame() {
this.setVisible(true);
this.setSize(500, 600);
this.setDefaultCloseOpera on(JFrame.EXIT_ON_CLOSE);
c = getContentPane();
c.setBackground(Color.cyan);
c.setLayout(null);
l1 = new JLabel("User name");
l1.setBounds(50, 100, 100, 10);
l2 = new JLabel("Password");
l2.setBounds(50, 150, 100, 10);
l3 = new JLabel("Qualifica on");
l3.setBounds(50, 200, 100, 10);
l4 = new JLabel("Gender");
l4.setBounds(50, 250, 100, 10);
l5 = new JLabel("Technologies");
l5.setBounds(50, 300, 100, 10);
l6 = new JLabel("Profession");
l6.setBounds(50, 350, 100, 10);
l7 = new JLabel("Address");
l7.setBounds(50, 400, 100, 10);
= new JTextField(20);
.setBounds(150, 90, 100, 30);
.setToolTipText("This is text field");
pf = new JPasswordField(20);
pf.setBounds(150, 140, 100, 30);
pf.setToolTipText("This is password field");
cb1 = new JCheckBox("BSC");
cb1.setBounds(150, 190, 60, 30);
cb2 = new JCheckBox("MCA");
cb2.setBounds(220, 190, 60, 30);
cb3 = new JCheckBox("PHD");
cb3.setBounds(290, 190, 60, 30);
rb1 = new JRadioBu on("Male");
rb1.setBounds(150, 240, 80, 30);
rb2 = new JRadioBu on("Female");
rb2.setBounds(250, 240, 80, 30);
Bu onGroup bg = new Bu onGroup();
bg.add(rb1);
bg.add(rb2);
String[] techs = {"c", "C++", "JAVA"};
l = new JList<>(techs);
l.setBounds(150, 280, 60, 60);
String[] prof = {"Student", "Business", "Teacher"};
cb = new JComboBox<>(prof);
cb.setBounds(150, 340, 80, 30);
ta = new JTextArea(5, 25);
ta.setBounds(150, 380, 100, 40);
b = new JBu on("Registra on");
b.setBounds(80, 450, 110, 40);
b.addAc onListener(this);
c.add(l1);
c.add( );
c.add(l2);
c.add(pf);
c.add(l3);
c.add(cb1);
c.add(cb2);
c.add(cb3);
c.add(l4);
c.add(rb1);
c.add(rb2);
c.add(l5);
c.add(l);
c.add(l6);
c.add(cb);
c.add(l7);
c.add(ta);
c.add(b);
}
public void ac onPerformed(Ac onEvent ae) {
uname = .getText();
upwd = String.valueOf(pf.getPassword());
if (cb1.isSelected()) {
uqual = uqual + cb1.getText() + " ";
if (cb2.isSelected()) {
uqual = uqual + cb2.getText() + " ";
if (cb3.isSelected()) {
uqual = uqual + cb3.getText() + " ";
if (rb1.isSelected()) {
ugen = rb1.getText();
if (rb2.isSelected()) {
ugen = rb2.getText();
List<String> selectedTechsList = l.getSelectedValuesList();
utech = selectedTechsList.toArray(new String[0]);
uprof = (String) cb.getSelectedItem();
uaddr = ta.getText();
DisplayFrame df = new DisplayFrame(); // Op onal: Display the informa on here
class DisplayFrame extends JFrame {
DisplayFrame() {
this.setVisible(true);
this.setSize(500, 500);
this.setBackground(Color.pink);
public void paint(Graphics g) {
Font f = new Font("arial", Font.BOLD, 25);
g.setFont(f);
g.drawString("Username:" + uname, 50, 100);
g.drawString("Password:" + upwd, 50, 150);
g.drawString("Qualifica on:" + uqual, 50, 200);
g.drawString("User Gender:" + ugen, 50, 250);
g.drawString("Technologies:" + String.join(", ", utech), 50, 300);
g.drawString("Profession:" + uprof, 50, 350);
g.drawString("Address:" + uaddr, 50, 400);
// DisplayFrame df = new DisplayFrame(); // You might want to create DisplayFrame here
public sta c void main(String args[]) {
Registra onFrame rec = new Registra onFrame();