diff --git a/LAB7/Runnableinterface.java b/LAB7/RunnableInterface.java similarity index 99% rename from LAB7/Runnableinterface.java rename to LAB7/RunnableInterface.java index 4562de4..5525e6a 100644 --- a/LAB7/Runnableinterface.java +++ b/LAB7/RunnableInterface.java @@ -20,10 +20,7 @@ public static void main(String[] args) { i t = new i(); Thread a = new Thread(t); a.start(); - - } - } diff --git a/LAB7/Runnableinterfacedemo.java b/LAB7/RunnableInterfaceDemo.java similarity index 99% rename from LAB7/Runnableinterfacedemo.java rename to LAB7/RunnableInterfaceDemo.java index a2416da..96b69a4 100644 --- a/LAB7/Runnableinterfacedemo.java +++ b/LAB7/RunnableInterfaceDemo.java @@ -12,6 +12,7 @@ public void run(){ } } } + class ThreadB implements Runnable{ @Override public void run() { @@ -22,6 +23,7 @@ public void run() { } } } + public class RunnableInterfaceDemo { public static void main(String[] args){ ThreadA a=new ThreadA(); diff --git a/LAB7/ThreadDemo.java b/LAB7/ThreadDemo.java index aa42222..f6843b7 100644 --- a/LAB7/ThreadDemo.java +++ b/LAB7/ThreadDemo.java @@ -1,10 +1,18 @@ /* 1. Use the concept of creating thread by extending the Thread class to convert the following program that prints the output in the interval of 1 second.*/ + class Hi extends Thread{ public void run(){ for(int i=1;i<=5;i++){ + try { + Thread.sleep(1000); + + } catch (Exception e) { + } + System.out.println("HI - " + i); + } } } diff --git a/LAB7/Threadinterval.java b/LAB7/ThreadInterval.java similarity index 99% rename from LAB7/Threadinterval.java rename to LAB7/ThreadInterval.java index ba9853f..e1ee62a 100644 --- a/LAB7/Threadinterval.java +++ b/LAB7/ThreadInterval.java @@ -20,8 +20,5 @@ public static void main(String[] args) { m t = new m(); Thread a = new Thread(t); a.start(); - - } - } diff --git a/LAB7/ThreadPriorites.java b/LAB7/ThreadPriorites.java new file mode 100644 index 0000000..d8291d0 --- /dev/null +++ b/LAB7/ThreadPriorites.java @@ -0,0 +1,36 @@ + /* 4. Run the following program and learn the concept of thread priority. */ + +class myThread extends Thread{ + public void run() { + System.out.println("Inside run method"); + } +} + +public class ThreadPriorites { + public static void main(String[] args) { + myThread t1 = new myThread(); + myThread t2 = new myThread(); + myThread t3 = new myThread(); + + System.out.println("t1 thread priority : " + t1.getPriority()); // Default 5 + System.out.println("t2 thread priority : " + t2.getPriority()); // Default 5 + System.out.println("t3 thread priority : " + t3.getPriority()); // Default 5 + + t1.setPriority(2); + t2.setPriority(5); + t3.setPriority(8); + + // t3.setPriority(21); will throw IllegalArgumentException + System.out.println("t1 thread priority : " + t1.getPriority()); //2 + System.out.println("t2 thread priority : " + t2.getPriority()); //5 + System.out.println("t3 thread priority : " + t3.getPriority());//8 + + // Main thread + System.out.print(Thread.currentThread().getName()); + System.out.println("Main thread priority : "+ Thread.currentThread().getPriority()); + + // Main thread priority is set to 10 + Thread.currentThread().setPriority(10); + System.out.println("Main thread priority : "+ Thread.currentThread().getPriority()); + } +} \ No newline at end of file diff --git a/LAB7/Threadpriorites.java b/LAB7/Threadpriorites.java deleted file mode 100644 index 4af4e75..0000000 --- a/LAB7/Threadpriorites.java +++ /dev/null @@ -1,35 +0,0 @@ - /* 4. Run the following program and learn the concept of thread priority. */ - - class myThread extends Thread{ -public void run() - { - System.out.println("Inside run method"); - } -} -public class ThreadPriorites { -public static void main(String[] args) { -myThread t1 = new myThread(); -myThread t2 = new myThread(); -myThread t3 = new myThread(); - - System.out.println("t1 thread priority : " + t1.getPriority()); // Default 5 - System.out.println("t2 thread priority : " + t2.getPriority()); // Default 5 -System.out.println("t3 thread priority : " + t3.getPriority()); // Default 5 - - t1.setPriority(2); - t2.setPriority(5); - t3.setPriority(8); - -// t3.setPriority(21); will throw IllegalArgumentException - System.out.println("t1 thread priority : " + t1.getPriority()); //2 - System.out.println("t2 thread priority : " + t2.getPriority()); //5 -System.out.println("t3 thread priority : " + t3.getPriority());//8 - // Main thread - System.out.print(Thread.currentThread().getName()); - System.out.println("Main thread priority : "+ Thread.currentThread().getPriority()); - -// Main thread priority is set to 10 - Thread.currentThread().setPriority(10); - System.out.println("Main thread priority : "+ Thread.currentThread().getPriority()); - } -} \ No newline at end of file diff --git a/LAB8 - GUI/EventDemo.java b/LAB8 - GUI/EventDemo.java new file mode 100644 index 0000000..09a0064 --- /dev/null +++ b/LAB8 - GUI/EventDemo.java @@ -0,0 +1,31 @@ +import javax.swing.*; +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; + +public class EventDemo extends JFrame implements ActionListener { + JButton b; + JTextField tf; + + EventDemo(){ + b=new JButton("Click Me"); + tf=new JTextField(20); + b.setBounds(20,80,120,30); + tf.setBounds(30, 40,260,30); + add(b); + add(tf);; + b.addActionListener(this); + setLayout(null); + setSize(300,300); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + } + + public void actionPerformed(ActionEvent ae){ + tf.setText("Welcome"); + } + + public static void main(String[] args) { + EventDemo ed=new EventDemo(); + } +} diff --git a/LAB8 - GUI/EventDemoo.java b/LAB8 - GUI/EventDemoo.java new file mode 100644 index 0000000..172d3e9 --- /dev/null +++ b/LAB8 - GUI/EventDemoo.java @@ -0,0 +1,29 @@ +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; +public class EventDemoo extends JFrame implements ActionListener { + JButton b; + JLabel l; + int count=0; + EventDemoo(){ + b=new JButton("Click Here"); + l=new JLabel(); + b.setBounds(20,80,120,30); + l.setBounds(30, 40,260,30); + add(b); + add(l);; + b.addActionListener(this); + setLayout(null); + setSize(300,300); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + } + + public void actionPerformed(ActionEvent ae){ + l.setText(String.valueOf(++count)); + } + + public static void main(String[] args) { + EventDemoo ed=new EventDemoo(); + } +} diff --git a/LAB8 - GUI/GUIDemo.java b/LAB8 - GUI/GUIDemo.java new file mode 100644 index 0000000..9dfb1ec --- /dev/null +++ b/LAB8 - GUI/GUIDemo.java @@ -0,0 +1,38 @@ +import java.swing.*; +import java.awt.*; + +public class GUIDemo{ + public static void main(String[] args){ + + + JFrame f=new JFrame('Registration'); + + JLabel lHeader=new JLabel("Student Registration"); + lHeader.setBounds(260,10,120,20); + f.add(lHeader); + + JLabel lName = new JLabel("Name:"); + lName.setBounds(30,50,70,10); + f.add(lName); + + JTextField tName=new JTextField(); + tName.setBounds(100,45,120,20); + f.add(tName); + + String[] age={"17","18","19","20"}; + JLabel lAge= new JLabel("Age"); + lAge.setBounds(30,80,70,20); + f.add(lAge); + + JcomboBox cAge=new JcomboBox(age); + cAge.setBounds(100,100,70,20); + f.add( + + ) + + f.setLayout(null); + f.setSize(800,600); + f.setVisible(true); + f.setDefaultCloseOperation(f.EXIT_ON_CLOSE); + } +} \ No newline at end of file diff --git a/LAB8 - GUI/Main.java b/LAB8 - GUI/Main.java new file mode 100644 index 0000000..3e59c38 --- /dev/null +++ b/LAB8 - GUI/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/LAB8 - GUI/form.java b/LAB8 - GUI/form.java new file mode 100644 index 0000000..921fd8b --- /dev/null +++ b/LAB8 - GUI/form.java @@ -0,0 +1,93 @@ +import javax.swing.*; +import java.awt.*; +public class form { + public static void main(String[] args) { + JFrame f=new JFrame("Registration"); + + JLabel lHeader=new JLabel("STUDENT'S REGISTRATION FORM"); + lHeader.setBounds(200,20,300,30); + f.add(lHeader); + + JLabel lName= new JLabel("Name : "); + lName.setBounds(100,60,100,30); + f.add(lName); + + JTextField tName=new JTextField(100); + tName.setBounds(200,60,300,30); + f.add(tName); + + JLabel lAge=new JLabel("Age : "); + lAge.setBounds(100,100,100,30); + f.add(lAge); + + /* JTextField tAge=new JTextField(80); + tAge.setBounds(300,100,100,30); + f.add(tAge); + */ + String age[]={"17","18","19","20","21"}; + JComboBox cAge=new JComboBox(age); + cAge.setBounds(200,100,300,30); + f.add(cAge); + + JLabel lGender=new JLabel("Gender : "); + lGender.setBounds(100,140,100,30); + f.add(lGender); + + JRadioButton rMale=new JRadioButton("Male"); + rMale.setBounds(200,140,100,30); + f.add(rMale); + + JRadioButton rFemale=new JRadioButton("Female"); + rFemale.setBounds(300,140,100,30); + f.add(rFemale); + + JRadioButton rOthers=new JRadioButton("Others"); + rOthers.setBounds(400,140,100,30); + f.add(rOthers); + + JLabel lHobbies = new JLabel("Hobbies : "); + lHobbies.setBounds(100,180,100,30); + f.add(lHobbies); + + JCheckBox cb1=new JCheckBox("Playing"); + cb1.setBounds(200,180,100,30); + f.add(cb1); + + JCheckBox cb2=new JCheckBox("Singing"); + cb2.setBounds(300,180,100,30); + f.add(cb2); + + JCheckBox cb3=new JCheckBox("Coding"); + cb3.setBounds(400,180,100,30); + f.add(cb3); + + JLabel lCountries =new JLabel("Countries : "); + lCountries.setBounds(100,220,100,30); + f.add(lCountries); + + String [] countries={"Nepal","India","USA","England"}; + JComboBox tb=new JComboBox(countries); + tb.setBounds(200,220,300,30); + f.add(tb); + + JLabel lComments =new JLabel("Comments : "); + lComments.setBounds(100,260,100,30); + f.add(lComments); + + JTextArea tComments=new JTextArea(); + tComments.setBounds(200,260,300,90); + f.add(tComments); + + JButton btn1=new JButton("SUBMIT"); + JButton btn2=new JButton("CANCEL"); + btn1.setBounds(220,400,100,30); + btn2.setBounds(380,400,100,30); + f.add(btn1); + f.add(btn2); + + f.setLayout(null); + f.setSize(600,600); + f.setVisible(true); + f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + } +} diff --git a/LAB8 - GUI/keyDemo.java b/LAB8 - GUI/keyDemo.java new file mode 100644 index 0000000..f9eeaff --- /dev/null +++ b/LAB8 - GUI/keyDemo.java @@ -0,0 +1,38 @@ +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; + +public class keyDemo extends JFrame implements KeyListener{ + JLabel l; + JTextArea ta; + keyDemo(){ + l=new JLabel("Key here"); + ta=new JTextArea(); + l.setBounds(70,70,150,30); + ta.setBounds(30,120,150,30); + add(l); + add(ta); + ta.addKeyListener(this); + setSize(500,500); + setTitle("Key Example"); + setLayout(null); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + } + + public static void main(String[] args) { + keyDemo k=new keyDemo(); + } + + public void keyTyped(KeyEvent ke){ + l.setText("Key Typed !☺ "); + } + + public void keyPressed(KeyEvent ke){ + l.setText("Key Pressed ! ☻"); + } + + public void keyReleased(KeyEvent ke){ + l.setText("key Released ! ☹"); + } +} diff --git a/LAB8 - GUI/mouseDemo.java b/LAB8 - GUI/mouseDemo.java new file mode 100644 index 0000000..c4c7584 --- /dev/null +++ b/LAB8 - GUI/mouseDemo.java @@ -0,0 +1,47 @@ +import javax.swing.*; +import java.awt.event.*; + +public class mouseDemo extends JFrame implements MouseListener{ + JLabel l; + JTextArea ta; + mouseDemo(){ + l=new JLabel("Mouse here"); + ta=new JTextArea(); + l.setBounds(70,70,150,30); + ta.setBounds(30,120,350,80); + add(l); + add(ta); + ta.addMouseListener(this); + setSize(500,500); + setTitle("Mouse Events Example"); + setLayout(null); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + } + + public static void main(String[] args) { + mouseDemo m=new mouseDemo(); + } + + public void mouseClicked(MouseEvent me){ + l.setText("Mouse Clicked !☺ "); + } + + public void mouseEntered(MouseEvent me){ + l.setText("Mouse Entered ! ☻"); + } + + public void mouseExited(MouseEvent me){ + l.setText("Mouse Exited ! ☹"); + } + + + public void mousePressed(MouseEvent me){ + l.setText("Mouse Pressed ! ☹"); + } + + + public void mouseReleased(MouseEvent me){ + l.setText("Mouse Released ! ☹"); + } +}