"As each child grows older, he/she needs to learn in order to survive; teachers are the ones to instill knowledge (DeRoy)." Therefore i have made a simple java program using Swings to wish all the teachers a very happy teachers Day.
Code Explaination
In this code there are 3 classes:
1.teacher class
2.Registration
3.WiishCard classes
The teacher class contains the main method, Registration class contain codes that allows user to register and the wiish class contains the wish for the teacher
Teacher Class
public class teacher
{
public static void main(String[] args)
{
Registration R1 = new Registration();
R1.Details();
}
}
Registration class
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class Registration extends JFrame
{
private static final long serialVersionUID = -7614034343348966109L;
Registration()
{
setVisible(true);
setTitle("Register");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 570, 430);
}
JPanel cP;
JLabel l1,L2,L3,L4;
public JRadioButton r1,r2;
JTextField t1,t2;
JButton jb1;
public void Details()
{
cP = new JPanel();
cP.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(cP);
cP.setLayout(null);
l1 = new JLabel("REGISTER");
l1.setForeground(Color.BLUE);
l1.setFont(new Font("Times New Roman", Font.PLAIN, 30));
l1.setBounds(170, 11, 170, 44);
cP.add(l1);
L2 = new JLabel("Tutor Name:");
L2.setForeground(Color.BLUE);
L2.setFont(new Font("Times New Roman", Font.PLAIN, 20));
L2.setBounds(10, 152, 163, 44);
cP.add(L2);
L3 = new JLabel("Tutor Gender:");
L3.setForeground(Color.BLUE);
L3.setFont(new Font("Times New Roman", Font.PLAIN, 20));
L3.setBounds(10, 207, 163, 44);
cP.add(L3);
L4 = new JLabel("Student Name:");
L4.setForeground(Color.BLUE);
L4.setFont(new Font("Times New Roman", Font.PLAIN, 20));
L4.setBounds(10, 262, 163, 44);
cP.add(L4);
r1 = new JRadioButton("Male");
r1.setFont(new Font("Times New Roman", Font.PLAIN, 20));
r1.setBounds(153, 220, 109, 23);
cP.add(r1);
r2 = new JRadioButton("Female");
r2.setFont(new Font("Times New Roman", Font.PLAIN, 20));
r2.setBounds(296, 218, 109, 23);
cP.add(r2);
t1 = new JTextField();
t1.setBounds(153, 166, 219, 20);
cP.add(t1);
t1.setColumns(10);
ButtonGroup bg = new ButtonGroup();
bg.add(r1);
bg.add(r2);
jb1 = new JButton("WISH");
jb1.setFont(new Font("Times New Roman", Font.PLAIN, 15));
jb1.setBounds(193, 336, 109, 31);
cP.add(jb1);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
wish();
WiishCards n1 = new WiishCards();
String a,b;
if(r1.isSelected())
{
a= t1.getText();
a = "Sir " + a;
}
else
{
a=t1.getText();
a = "Madam " + a;
}
b = t2.getText();
n1.wish(a,b);
}
private void wish()
{
setVisible(false);
}
});
t2 = new JTextField();
t2.setColumns(10);
t2.setBounds(153, 276, 219, 20);
cP.add(t2);
}
}
WiishCard class
import java.awt.Color;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class WiishCards extends JFrame
{
public WiishCards()
{
setVisible(true);
setTitle("Wishing Cards");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 570, 430);
}
public void wish(String a, String b )
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 570, 430);
getContentPane().setLayout(null);
JLabel l2= new JLabel("HAPPY TEACHERS DAY ");
l2.setFont(new Font("MV Boli", Font.PLAIN, 35));
l2.setForeground(Color.BLUE);
l2.setBounds(39, 24, 478, 47);
getContentPane().add(l2);
JLabel l1 = new JLabel();
l1.setText(a);
l1.setFont(new Font("Tempus Sans ITC", Font.BOLD | Font.ITALIC, 30));
l1.setForeground(Color.BLUE);
l1.setBounds(39, 82, 478, 38);
getContentPane().add(l1);
JLabel L3 = new JLabel("THANKYOU ");
L3.setForeground(Color.GREEN);
L3.setFont(new Font("Viner Hand ITC", Font.PLAIN, 26));
L3.setBounds(177, 131, 166, 55);
getContentPane().add(L3);
JLabel l4= new JLabel("For teaching us efficiently even during hard times)");
l4.setForeground(Color.MAGENTA);
l4.setFont(new Font("Viner Hand ITC", Font.PLAIN, 17));
l4.setBounds(20, 189, 434, 70);
getContentPane().add(l4);
JLabel l5 = new JLabel("it has been an honor to get to learn so many things from you");
l5.setForeground(Color.MAGENTA);
l5.setFont(new Font("Viner Hand ITC", Font.PLAIN, 17));
l5.setBounds(26, 231, 505, 75);
getContentPane().add(l5);
JLabel l6 = new JLabel();
l6.setText("Wish From: " + b);
l6.setForeground(Color.GREEN);
l6.setFont(new Font("Times New Roman", Font.PLAIN, 15));
l6.setBounds(53, 317, 434, 63);
getContentPane().add(l6);
}
}
0 Comments:
Post a Comment