Java_Assignment_2_Solutions (1)
Java_Assignment_2_Solutions (1)
Exception.
try {
int result = 10 / 0;
System.out.println(result);
} catch (ArithmeticException e) {
2. Write a program to implement the concept of Exception Handling using throw keyword.
} else {
System.out.println("Welcome to vote!");
}
public static void main(String[] args) {
try {
validate(16);
} catch (IllegalArgumentException e) {
import java.io.FileWriter;
import java.io.IOException;
} catch (IOException e) {
}
4. Write a program to draw different shapes in an applet using graphic class.
import java.applet.Applet;
import java.awt.Graphics;
import java.applet.Applet;
import java.awt.Graphics;
6. Write a java program which will create a window and an empty area within that window
CreateWindow() {
setTitle("My Window");
setSize(400, 300);
setVisible(true);
new CreateWindow();
import java.awt.*;
import java.awt.event.*;
Label label;
KeyboardEventDemo() {
addKeyListener(this);
setSize(400, 300);
setLayout(null);
setVisible(true);
new KeyboardEventDemo();
import java.awt.*;
import java.awt.event.*;
public class MouseEventDemo extends Frame implements MouseListener {
Label label;
MouseEventDemo() {
add(label);
addMouseListener(this);
setSize(400, 300);
setLayout(null);
setVisible(true);
new MouseEventDemo();
}
9. Write a program to enter two numbers in two different text fields, add a button, and display
import java.awt.*;
import java.awt.event.*;
Button addButton;
SumCalculatorGUI() {
tf3.setEditable(false);
addButton.addActionListener(this);
add(tf1);
add(tf2);
add(tf3);
add(addButton);
setSize(400, 300);
setLayout(null);
setVisible(true);
tf3.setText(String.valueOf(num1 + num2));
new SumCalculatorGUI();