Aim Write a program to implement Swing .
/*
Aim Write a program to implement Swing .
*/
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class swing extends JFrame implements ActionListener
{
JButton on,off;
JLabel water_level,Fuse_status,Line_status;
JTextField msg;
Font fnt;
JCheckBox line1,line2,line3,fuse1,fuse2,fuse3;
swing()
{
JPanel p1 = (JPanel)(getContentPane());
setBounds(50,50,500,500);
p1.setLayout(null);
fnt = new Font ("arial",Font.BOLD+Font.ITALIC,20);
on=new JButton("ON");
off=new JButton("off");
water_level=new JLabel("Water Status ");
Fuse_status=new JLabel("Fuse status ");
Line_status=new JLabel("Line status ");
msg = new JTextField(50);
UIManager.put("ProgressBar.background", Color.RED);
UIManager.put("ProgressBar.foreground", Color.GREEN);
//UIManager.put("ProgressBar.selectionBackground",Color.YELLOW);
JProgressBar water_progress=new JProgressBar(JProgressBar.VERTICAL,0,100);
water_progress.setValue(50);
water_progress.setStringPainted(true);
line1=new JCheckBox("Line 1");
line2=new JCheckBox("Line 2");
line3=new JCheckBox("Line 3");
fuse1=new JCheckBox("Fuse 1");
fuse2=new JCheckBox("Fuse 2");
fuse3=new JCheckBox("Fuse 3");
water_level.setBounds(30,30,150,50);
water_progress.setBounds(30,80,100,130);
Line_status.setBounds(200,30,150,50);
line1.setBounds(200,100,150,20);
line2.setBounds(200,140,150,20);
line3.setBounds(200,180,150,20);
Fuse_status.setBounds(350,30,120,50);
fuse1.setBounds(350,100,120,20);
fuse2.setBounds(350,140,120,20);
fuse3.setBounds(350,180,120,20);
msg.setBounds(30,250,440,100);
on.setBounds(30,370,219,70);
off.setBounds(251,370,219,70);
on.addActionListener(this);
off.addActionListener(this);
p1.setFont(fnt);
p1.add(on);
p1.add(off);
p1.add(water_level);
p1.add(Fuse_status);
p1.add(Line_status);
p1.add(msg);
p1.add(line1);
p1.add(line2);
p1.add(line3);
p1.add(fuse1);
p1.add(fuse2);
p1.add(fuse3);
p1.add(water_progress);
//drawLine(50,50,150,150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==on)
if(line1.isSelected())
if(line2.isSelected())
if(line3.isSelected())
if(fuse1.isSelected())
if(fuse2.isSelected())
if(fuse3.isSelected())
msg.setText(" !!!!! Motor is ON !!!!!");
else
msg.setText("ERROR!!! Fuse 3 goan");
else
if(fuse3.isSelected())
msg.setText("ERROR!!! Fuse 2 goan");
else
msg.setText("ERROR!!! Fuse 2 and 3 are goan");
else
if(fuse2.isSelected())
if(fuse3.isSelected())
msg.setText("ERROR!!! Fuse 1 goan");
else
msg.setText("ERROR!!! Fuse 1 and 3 are goan");
else
if(fuse3.isSelected())
msg.setText("ERROR!!! Fuse 1 and 2 are NOT present");
else
msg.setText("ERROR!!! All Fuse are goan");
else
msg.setText("ERROR!!! Line 3 is NOT present");
else
if(line3.isSelected())
msg.setText("ERROR!!! Line 2 is NOT present");
else
msg.setText("ERROR!!! Line 2 and 3 are NOT present");
else
if(line2.isSelected())
if(line3.isSelected())
msg.setText("ERROR!!! Line 1 is NOT present");
else
msg.setText("ERROR!!! Line 1 and 3 are NOT present");
else
if(line3.isSelected())
msg.setText("ERROR!!! Line 1 and 2 are NOT present");
else
msg.setText("ERROR!!! ALL 3 Lines are NOT present");
else
if(ae.getSource()==off)
msg.setText(" !!!!! Motor is OFF !!!!!");
}
public static void main(String argv[])
{
swing obj=new swing();
}
}
OUTPUT : 1) COMPILE IT WITH JAVAC
2) RUN BY JAVA
you will found following output on screen..