Java Oop Programs
Java Oop Programs
Java Oop Programs
Division.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
frame.add(label1);
frame.add(textField1);
frame.add(label2);
frame.add(textField2);
frame.add(label3);
frame.add(textField3);
frame.add(button);
frame.setLayout(new FlowLayout());
frame.setSize(300, 300);
frame.setVisible(true);
button.addActionListener(new ActionListener() {
@Override
try{
String s;
s=""+(num1/num2);
textField3.setText(s);
catch(ArithmeticException a)
JOptionPane.showMessageDialog(null,"Divide by zero");
catch(NumberFormatException b)
JOptionPane.showMessageDialog(null,"NumberFormatException");
});
}
Develop a java program to implement mouse events like mouse pressed, mouse released,
and mouse moved by means of adapter classes.
MouseListenerExample.java
import java.awt.*;
import java.awt.event.*;
Label l;
MouseListenerExample(){
addMouseListener(this);
l=new Label();
l.setBounds(20,50,100,20);
add(l);
setSize(300,300);
setLayout(null);
setVisible(true);
l.setText("Mouse Clicked");
l.setText("Mouse Entered");
l.setText("Mouse Exited");
}
l.setText("Mouse Pressed");
l.setText("Mouse Released");
new MouseListenerExample();