SAMPLE PROGRAM
PROGRAM 4:
SOURCE CODE:
import [Link].*;
import [Link].*;
class Server {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(1234);
[Link]("Server is running...");
Socket socket1 = [Link]();
Socket socket2 = [Link]();
new ClientHandler(socket1, socket2).start();
class ClientHandler extends Thread {
private Socket socket1;
private Socket socket2;
private BufferedReader in1;
private BufferedReader in2;
private PrintWriter out1;
private PrintWriter out2;
public ClientHandler(Socket socket1, Socket socket2) throws IOException {
this.socket1 = socket1;
this.socket2 = socket2;
in1 = new BufferedReader(new InputStreamReader([Link]()));
out1 = new PrintWriter([Link](), true);
in2 = new BufferedReader(new InputStreamReader([Link]()));
out2 = new PrintWriter([Link](), true);
public void run() {
try {
while (true) {
String message1 = [Link]();
if (message1 == null) {
break;
[Link]("Client 1: " + message1);
[Link]("Client 1: " + message1);
String message2 = [Link]();
if (message2 == null) {
break;
[Link]("Client 2: " + message2);
[Link]("Client 2: " + message2);
} catch (IOException e) {
[Link]("Client disconnected");
} finally {
try {
[Link]();
[Link]();
} catch (IOException e) {
[Link]();
class Client {
public static void main(String[] args) throws IOException {
Socket socket = new Socket("localhost", 1234);
BufferedReader in = new BufferedReader(new InputStreamReader([Link]()));
PrintWriter out = new PrintWriter([Link](), true);
BufferedReader consoleInput = new BufferedReader(new InputStreamReader([Link]));
while (true) {
[Link]("Enter message: ");
String message = [Link]();
[Link](message);
String response = [Link]();
[Link](response);
OUTPUT:
PROGRAM 6:
SOURCE CODE:
import [Link].*;
public class FirstSwingExample {
public static void main(String[] args) {
JFrame f=new JFrame();//creating instance of JFrame
JButton b=new JButton("click");//creating instance of JButton
[Link](130,100,100, 40);//x axis, y axis, width, height
[Link](b);//adding button in JFrame
[Link](400,500);//400 width and 500 height
[Link](null);//using no layout managers
[Link](true);//making the frame visible
}
OUTPUT:
PROGRAM 6:
SOURCE CODE:
import [Link].*;
class MenuExample
JMenu menu, submenu;
JMenuItem i1, i2, i3, i4, i5;
MenuExample(){
JFrame f= new JFrame("Menu and MenuItem Example");
JMenuBar mb=new JMenuBar();
menu=new JMenu("Menu");
submenu=new JMenu("Sub Menu");
i1=new JMenuItem("Item 1");
i2=new JMenuItem("Item 2");
i3=new JMenuItem("Item 3");
i4=new JMenuItem("Item 4");
i5=new JMenuItem("Item 5");
[Link](i1); [Link](i2); [Link](i3);
[Link](i4); [Link](i5);
[Link](submenu);
[Link](menu);
[Link](mb);
[Link](400,400);
[Link](null);
[Link](true);
public static void main(String args[])
new MenuExample();
}}
OUTPUT: