PROGRAM:
import [Link];
public class Extractedstring
public static void main(String[]args)
Scanner in=new Scanner ([Link]);
[Link]("Enter a string:");
String os=[Link]();
[Link]("Enter the Starting Index Value:");
int n=[Link]();
[Link]("Enter the Ending Index Value:");
int m=[Link]();
String ES=[Link](n,m); [Link]("Original String:"+os);
[Link]("Extracted String:"+ES);
}
OUTPUT:
PROGRAM:
import [Link];
interface flyable
void fly();
interface walkable
void walk();
class Bird implements flyable,walkable
Scanner sc= new Scanner([Link]);
public void fly()
[Link]("Name the Bird That Fly:");
String f=[Link]();
}
public void walk()
[Link]("Name the Bird That walk:");
String w=[Link]();
public class Multipleinheritancedemo
public static void main(String[]args)
Bird nk=new Bird();
[Link]();
[Link]();
[Link]("SAVE BIRDS");
}
OUTPUT:
PROGRAM:
import [Link];
import [Link];
import [Link];
class PayoutOutOfBoundsException extends ArithmeticException
{
public PayoutOutOfBoundsException(String message)
{
super(message);
}
}
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader in = new BufferedReader(new
InputStreamReader([Link]));
[Link]("ENTER A:");
int a = [Link]([Link]());
[Link]("ENTER B:");
int b = [Link]([Link]());
int c;
try
{
c = b - a;
if (c > 32768)
{
throw new PayoutOutOfBoundsException("PAY OUT OF BOUNDS");
}
[Link]("ANSWER: " + c);
}
catch (PayoutOutOfBoundsException e)
{
[Link]([Link]());
}
}
}
OUTPUT 1:
Enter Employee Salary:
5000
The given salary of Employee is 5000
OUTPUT 2:
Enter Employee Salary:
1500
PayOutOfBoundsException: Salary must be 3000 to 10000
PROGRAM:
import [Link].*;
public class MultiThread extends Thread
private int tableNumber;
private int max;
public MultiThread(int tableNumber, int max)
[Link] = tableNumber;
[Link] = max;
// @Override
public void run()
for (int i = 1; i <= max; i++)
[Link](tableNumber + " x " + i + " = " + (tableNumber * i));
try
[Link](1000); // Add a slight delay to better visualize the output
catch (InterruptedException e)
[Link]();
public static void main(String[] args)
int limit = 10;
Scanner in =new Scanner([Link]);
[Link]("Enter three numbers for multiplication tables: ");
int x=[Link]();
int y=[Link]();
int z=[Link]();
// Create three threads with different priorities
MultiThread t1 = new MultiThread(x, limit);
MultiThread t2 = new MultiThread(y, limit);
MultiThread t3 = new MultiThread(z, limit);
// Set different priorities to the threads (MIN_PRIORITY = 1,
MAX_PRIORITY = 10)
[Link](Thread.MIN_PRIORITY);
[Link](Thread.NORM_PRIORITY);
[Link](Thread.MAX_PRIORITY);
// Start the threads
[Link]();
[Link]();
[Link]();
}
OUTPUT:
Enter three numbers for multiplication tables: 2
2x1=2
3x1=3
5x1=5
2x2=4
3x2=6
5 x 2 = 10
2x3=6
3x3=9
5 x 3 = 15
2x4=8
3 x 4 = 12
5 x 4 = 20
2 x 5 = 10
3 x 5 = 15
5 x 5 = 25
2 x 6 = 12
3 x 6 = 18
5 x 6 = 30
2 x 7 = 14
3 x 7 = 21
5 x 7 = 35
2 x 8 = 16
3 x 8 = 24
5 x 8 = 40
2 x 9 = 18
3 x 9 = 27
5 x 9 = 45
2 x 10 = 20
3 x 10 = 30
5 x 10 = 50
PROGRAM:
import [Link].*;
import [Link].*;
public class ShapeDrawer extends JPanel
@Override
protected void paintComponent(Graphics g)
[Link](g);
// Set the background color to white
setBackground([Link]);
// Draw a red circle
[Link]([Link]);
[Link](50, 50, 100, 100);
// Draw a blue rectangle
[Link]([Link]);
[Link](200, 50, 150, 100);
// Draw a green triangle
[Link]([Link]);
int[] xPoints = {300, 350, 400};
int[] yPoints = {150, 50, 150};
[Link](xPoints, yPoints, 3);
// Draw a yellow ellipse
[Link]([Link]);
[Link](450, 50, 150, 75);
public static void main(String[] args)
JFrame frame = new JFrame("Shape Drawer");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new ShapeDrawer());
[Link](600, 200);
[Link](true);
}
OUTPUT:
PROGRAM:
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class MultiSelectionListbox extends JFrame
{
public JLabel label;
public JButton submit;
public JList<String> list1, list2;
public MultiSelectionListbox()
{
setTitle("Multiple Selection ListBox");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setLayout(new FlowLayout([Link]));
String values[] = {"C", "C++", "Java", "Python", "R", "HTML", "XML",
"CSS", "PHP"};
label = new JLabel("Which Languages do you know?");
list1 = new JList<>(values);
list2 = new JList<>();
[Link](ListSelectionModel.MULTIPLE_INTERVAL_SEL
ECTION);
submit = new JButton("Submit");
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
[Link]([Link]().toArray(new String[0]));
}
};
add(label);
add(new JScrollPane(list1));
add(submit);
add(new JScrollPane(list2));
setVisible(true);
}
public static void main(String[] args)
{
new MultiSelectionListbox();
}
}
OUTPUT:
PROGRAM:
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class UserForm
public static void main(String[] args)
// Create the main frame
JFrame frame = new JFrame("User Profile Form");
[Link](320, 500);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new FlowLayout([Link],20,25));
// Create labels and text fields
JLabel nameLabel = new JLabel("Name:");
JTextField name = new JTextField(20);
JLabel ageLabel = new JLabel("Age:");
JTextField age = new JTextField(20);
JLabel qualificationLabel = new JLabel("Qualification:");
JTextField qualification = new JTextField(20);
JLabel addressLabel = new JLabel("Address:");
JTextArea address = new JTextArea(5, 20);
// Create a button to trigger the action
JButton submit = new JButton("Submit");
// Add components to the frame
[Link](nameLabel);
[Link](name);
[Link](ageLabel);
[Link](age);
[Link](qualificationLabel);
[Link](qualification);
[Link](addressLabel);
[Link](new JScrollPane(address));
[Link](submit);
// Create ActionListener for the button
[Link](new ActionListener()
public void actionPerformed(ActionEvent e)
// Display all values in a dialog box
String message = "Name: " + [Link]() + "\nAge: " + [Link]() +
"\nQualification: " + [Link]() + "\nAddress:\n" +
[Link]();
[Link](frame, message);
};
// Set frame visibility
[Link](true);
}
OUTPUT:
PROGRAM:
import [Link].*;
import [Link];
import [Link];
import [Link].*;
public class UserMenu
{
private static String text="";
private static JTextArea content;
public static void main(String[] args)
{
JFrame frame = new JFrame("Menu Program");
[Link](500, 500);
[Link](JFrame.EXIT_ON_CLOSE);
content=new JTextArea(50,50);
[Link](new Font("Serif",[Link],20));
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem newItem = new JMenuItem("New");
JMenuItem openItem = new JMenuItem("Open");
JMenuItem saveItem = new JMenuItem("Save");
JMenuItem exitItem = new JMenuItem("Exit");
[Link](newItem);
[Link](openItem);
[Link](saveItem);
[Link]();
[Link](exitItem);
JMenu editMenu = new JMenu("Edit");
JMenuItem cutItem = new JMenuItem("Cut");
JMenuItem copyItem = new JMenuItem("Copy");
JMenuItem pasteItem = new JMenuItem("Paste");
JMenuItem selectallItem = new JMenuItem("Select All");
[Link](cutItem);
[Link](copyItem);
[Link](pasteItem);
[Link](selectallItem);
JMenu helpMenu = new JMenu("Help");
JMenuItem aboutItem = new JMenuItem("About");
[Link](aboutItem);
[Link](fileMenu);
[Link](editMenu);
[Link](helpMenu);
[Link](menuBar);
[Link](new JScrollPane(content));
[Link](true);
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
[Link]("");
}
});
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
[Link](0);
}
});
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
text=(String)[Link]();
[Link]("");
}
});
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
text=(String)[Link]();
}
});
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int pos=[Link](); [Link](text,pos);
}
});
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
[Link]();
}
});
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
[Link](frame, "Menu Bar and Pull DownMenu
Program");
}
});
}
}
OUTPUT:
PROGRAM:`.
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class MouseClicks extends JFrame
public MouseClicks()
setTitle("Mouse Events ");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel l=new JLabel();
add(l);
addMouseListener(new MouseAdapter()
public void mouseClicked(MouseEvent e)
{
[Link]("Mouse Clicked");
public void mouseEntered(MouseEvent e)
[Link]("Mouse Entered");
public void mousePressed(MouseEvent e)
[Link]("Mouse Pressed");
public void mouseExited(MouseEvent e)
[Link]("Mouse Exited");
public void mouseReleased(MouseEvent e)
[Link]("Mouse Released");
}
});
setVisible(true);
public static void main(String[] args)
new MouseClicks();
}
OUTPUT:
PROGRAM:
import [Link].*;
import [Link].*;
import [Link].*;
public class ShapeDrawer extends JPanel implements MouseListener
private int x, y;
private boolean drawCircle = true;
public ShapeDrawer() { addMouseListener(this);
public void paintComponent(Graphics g)
[Link](g);
if (drawCircle) {[Link](x, y, 50, 50); // draw circle
else
{
if (x < y)
[Link](x, y, 50, 50); // draw square
else
[Link](x, y, 50, 50, 20, 20); // draw rectangle
public void mouseClicked(MouseEvent e)
x = [Link]();
y = [Link]();
drawCircle = drawCircle; // toggle between circle and rectangle repaint();
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public static void main(String[] args) {
JFrame frame = new JFrame("Shape Drawer");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new ShapeDrawer());
[Link](400, 400);
[Link](true);
}
OUTPUT: