Practical no.1(a):- package day1; public class construc { int age; String name; public construc() { System.out.println("Default Constructor"); } public construc(int age,String name) { this.age=age; this.name=name; } construc(construc cons) { this.age=cons.age; this.name=cons.name; } void show() { System.out.println(age+" "+name); } public static void main(String[] args) { construc c=new construc(19,"Bavadurga"); System.out.println("with argument constructor"); c.show(); System.out.println("copy constructor"); construc c1=new construc(c); c1.show(); } } Practical no.1(b):- package day1; class calculator{ void add() { int a=10; int b=50; int c=a+b; System.out.println(c); } void add(String name) { System.out.println(name); } void add(int num1,int num2) { int c=num1+num2; System.out.println(c); } } public class MethodOverloading { public static void main(String[] args) { calculator obj=new calculator(); obj.add("Bavadurga"); } } ...
Posts
Bouncing ball
- Get link
- X
- Other Apps
import javax.swing.*; import java.awt.*; import java.util.Random; public class BouncingBalls extends JFrame { private static final int WIDTH = 800; private static final int HEIGHT = 600; private static final int BALL_SIZE = 20; private static final Color[] COLORS = {Color.RED, Color.BLUE, Color.GREEN, Color.ORANGE, Color.MAGENTA}; private JPanel canvas; public BouncingBalls() { setTitle("Bouncing Balls"); setSize(WIDTH, HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); canvas = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); for (Ball ball : balls) {...
Swing aplicsn click
- Get link
- X
- Other Apps
Create a swing application that randomly changes color on button click. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Random; public class RandomColorChanger extends JFrame { private JPanel colorPanel; private JButton changeColorButton; public RandomColorChanger() { setTitle("Random Color Changer"); setSize(300, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Initialize components colorPanel = new JPanel(); colorPanel.setBackground(Color.WHITE); // Initial background color is white changeColorButton = new JButton("Change Color"); // Add action listener to the button changeColorButton.addActionListener(new ActionListener() { ...
JColorchooser
- Get link
- X
- Other Apps
Create a Swing application to demonstrate use of scrollpane to change its color selected using colour chooser. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ScrollPaneColorChooserDemo extends JFrame { private JTextArea textArea; private JScrollPane scrollPane; private JButton colorButton; public ScrollPaneColorChooserDemo() { setTitle("ScrollPane Color Chooser Demo"); setSize(400, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a JTextArea textArea = new JTextArea(10, 30); // Create a JScrollPane and add the JTextArea to it scrollPane = new JScrollPane(textArea); ...
- Get link
- X
- Other Apps
Write a program to define user defined exceptions and raise them as per the requirements. Code: class InvalidAgeException extends Exception { public InvalidAgeException(String message) { super(message); } } class User { private String name; private int age; public User(String name, int age) throws InvalidAgeException { if (age < 18) { throw new InvalidAgeException("Age must be 18 or older."); } this.name = name; this.age = age; } public void displayUserInfo() { System.out.println("Name: " + name); System.out.println("Age: " + age); } } public class Main { public static void main(String[] args) { try...