0% found this document useful (0 votes)
13 views

Java Practical Assignment 2

Computer Science

Uploaded by

love.vishwakarma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Java Practical Assignment 2

Computer Science

Uploaded by

love.vishwakarma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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