Java Practical Assignment 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

9.

Write an applet program that displays a simple message

import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
public void paint(Graphics g){
g.drawString("welcome to applet",100,100);
}
}

/*
<applet code="First.class" width="300" height="300">
</applet>
*/
10. Create a Java Program to check given number is Even or Odd
using Parametrized constructor and Scanner class.

import java.util.*;
class EvenOdd{
int num;

//Parametrized Constructor using Scanner class


EvenOdd(int n){
System.out.println("Enter any Number to Check Even or Odd");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
num = n;
}
//Function to check Even or Odd
void display(){
if(num%2==0){
System.out.println(num + " is Even");
}
else{
System.out.println(num + " is Odd");
}
}
//Main Fuction
public static void main(String args[]){
EvenOdd e1 = new EvenOdd(100);
e1.display();
}
}
11. Write a java program to demonstrate Java Swing by
Association inside constructor and using Inheritance.

import javax.swing.*;
public class Simple2 extends JFrame //inheriting JFrame
{
JFrame f;

Simple2()
{
JButton b=new JButton("click"); //create button
b.setBounds(130,100,100, 40);

add(b); //adding button on frame


setSize(400,500);
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
new Simple2();
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy