0% found this document useful (0 votes)
2 views

Java Gui

sample program in java gui

Uploaded by

Krishnmoorthi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java Gui

sample program in java gui

Uploaded by

Krishnmoorthi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

EX NO 09

GUI PRORAMS
01/10/2024

AIM:-

Develop a GUI application that calculates the tip amount based on the total bill and desired tip
percentage

PROGRAM:-

package Assignment9;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Group extends JFrame implements ActionListener{
private JLabel la;
private JRadioButton b1,b2,b3,b4;
private JTextField ag;
Group(){
setTitle("AGE GROUP IDENTIFIER");
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
JLabel sy=new JLabel("ENTER YOUR AGE : ");
ag=new JTextField(10);
b1=new JRadioButton("Child");
b2=new JRadioButton("Teenager");
b3=new JRadioButton("Adult");
b4=new JRadioButton("Senior");
JButton pl=new JButton("Submit");
la=new JLabel("");
add(sy);
add(ag);
add(b1);
add(b2);
add(b3);
add(b4);
add(pl);
add(la);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
pl.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
int age=Integer.parseInt(ag.getText());
if(e.getActionCommand().equals("Submit")) {
if(b1.isSelected() && age<=12)
la.setText("You are classified as a Child");
else if(b2.isSelected() && age>=13 && age<=19)
la.setText("You are classified as a Teenager");
else if(b3.isSelected() && age>=20 && age<=64)
la.setText("You are classified as a Adult");
else if(b4.isSelected() && age>=65)
la.setText("You are classified as a Senior");
else
la.setText("Invalid");
}
}
}
public class Age {
public static void main(String args[])
{
Group gp=new Group();
}
}

SAMPLE OUTPUT:-

AIM:-

Create a GUI application that allows users to select their favorite fruit using radio buttons.

PROGRAM:-

package Assignment9;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Fruit extends JFrame implements ActionListener{
JRadioButton r1,r2,r3,r4;
JLabel la;
Fruit(){
setTitle("FAVOURITE FRUIT");
setLayout(new FlowLayout());
setVisible(true);
r1=new JRadioButton("Apple");
r2=new JRadioButton("Banana");
r3=new JRadioButton("Orange");
r4=new JRadioButton("Grapes");
// lst.setBounds(100,50,150,80);
la=new JLabel("");
JButton b1=new JButton("Submit");
add(r1);
add(r2);
add(r3);
add(r4);
add(b1);
add(la);
b1.addActionListener(this);
r1.addActionListener(this);
r2.addActionListener(this);
r3.addActionListener(this);
r4.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Submit")) {
if(r1.isSelected())
la.setText("Selected : APPLE");
else if(r2.isSelected())
la.setText("Selected : BANANA");
else if(r3.isSelected())
la.setText("Selected : ORANGE");
else if(r4.isSelected())
la.setText("Selected : GRAPES");
}
}
}
public class Favourite {
public static void main(String[] args) {
Fruit f=new Fruit();

SAMPLE OUTPUT:-

AIM:-

Create a GUI application that allows users to select a subscription plan using radio buttons.

PROGRAM:-

package Assignment9;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Subscription extends JFrame implements ActionListener{
JLabel la;
JRadioButton b1,b2,b3;
Subscription(){
setTitle("Subscription plan");
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
b1=new JRadioButton("Basic");
b2=new JRadioButton("Standard");
b3=new JRadioButton("Premium");
JButton pl=new JButton("Choose Plan");
la =new JLabel("");
add(b1);
add(b2);
add(b3);
add(pl);
add(la);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
pl.addActionListener(this);
//b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Choose Plan")) {
if(b1.isSelected())
la.setText("Selected : Basic");
else if(b2.isSelected())
la.setText("Selected : Standard");
else if(b3.isSelected())
la.setText("Selected : Premium");
}
}
}
public class Plan {
public static void main(String[] args) {
Subscription s=new Subscription();

SAMPLE OUTPUT:-

You might also like