0% found this document useful (0 votes)
9 views6 pages

Slip 1

Uploaded by

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

Slip 1

Uploaded by

Virat Kohli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

SlipA1

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/* <APPLET CODE=ScrollingText.class WIDTH=400 HEIGHT=200 > </APPLET> */
public class Slip1A extends Applet implements Runnable
{
String msg="Welcome to Java Programming Language ....... ";
Thread t=null;
public void init()
{
setBackground(Color.cyan);
setForeground(Color.red);
t=new Thread(this);
t.start();
}
public void run()
{
char ch;
for(; ;)
{
try
{
repaint();
Thread.sleep(400);
ch=msg.charAt(0);
msg=msg.substring(1,msg.length());
msg+=ch;
}
catch(InterruptedException e)
{}
}
}
public void paint(Graphics g)
{
g.drawString(msg,10,10);
}
}

SlipA2

//Server
import java.awt.event.*;
import java.awt.*;
import java.net.*;
import java.io.*;

class new2 extends Frame implements ActionListener


{
static TextField t1=new TextField(20);
static Button b1=new Button("Send");
static TextArea ta=new TextArea(5,20);
static DataOutputStream dos;
static DataInputStream dis;
static ServerSocket st;
static Socket s;
static String r;
new2()
{
setLayout(new FlowLayout());
add(t1);add(b1);add(ta);
b1.addActionListener(this);
setVisible(true);
setSize(300,300);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if(cmd.equalsIgnoreCase("send"))
{
try
{
r=t1.getText();
dos.writeUTF(r);
}
catch(Exception p)
{
}
}
}
public static void main(String[] d ) throws IOException
{
new new2();

st=new ServerSocket(1281);
s=st.accept();
dos=new DataOutputStream(s.getOutputStream());
dis=new DataInputStream(s.getInputStream());
while(true)
{
r=dis.readUTF();
ta.append("client:"+r+"\n");
}
}

client

import java.awt.event.*;
import java.awt.*;
import java.net.*;
import java.io.*;

class new1 extends Frame implements ActionListener


{
static TextField t1=new TextField(20);
static Button b1=new Button("Send");
static TextArea ta=new TextArea(5,20);
static DataOutputStream dos;
static DataInputStream dis;
static Socket s;
static String r;
new1()
{
setLayout(new FlowLayout());
add(t1);add(b1);add(ta);
b1.addActionListener(this);
setVisible(true);
setSize(300,300);

}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
try
{
r=t1.getText();
dos.writeUTF(r);
}
catch(Exception p)
{
}
}
}
public static void main(String[] d ) throws IOException
{
new1 x= new new1();

s=new Socket("localhost",1281);
dos=new DataOutputStream(s.getOutputStream());
dis=new DataInputStream(s.getInputStream());
while(true)
{
r=dis.readUTF();
ta.append("Server:"+r+"\n");
}
}

SlipB1

XML FILE FIRST ACTIVITY

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/send_text_id"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:textSize="25dp"
android:hint="Input"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:layout_marginLeft="40dp"/>
<Button
android:id="@+id/send_button_id"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="send"
android:textStyle="bold"
android:layout_marginTop="150dp"
android:layout_marginLeft="150dp"/>
</RelativeLayout>

JAVA FILE FIRST ACTIVITY

package com.example.slip11;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button send_button;
EditText send_text;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send_button = (Button)findViewById(R.id.send_button_id);
send_text = (EditText)findViewById(R.id.send_text_id);
send_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
String str = send_text.getText().toString();
Intent intent = new Intent(getApplicationContext(),
Secndactivity.class);
intent.putExtra("message_key", str);
startActivity(intent);
}
});
}
}

XML FILE SECOND ACTIVITY

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/received_value_id"
android:layout_width="300dp"
android:layout_height="50dp"
android:textStyle="bold"
android:textSize="40dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="40dp"/>
</RelativeLayout>
JAVA FILE SECOND ACTIVITY

package com.example.slip11;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class Secndactivity extends AppCompatActivity {
TextView receiver_msg;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
receiver_msg = (TextView)findViewById(R.id.received_value_id);
Intent intent = getIntent();
String str = intent.getStringExtra("message_key");
receiver_msg.setText(str);
}
}

SlipB2

XML FILE

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show progress dialog"
android:layout_gravity="center"
android:layout_marginStart="50dp"/>
</LinearLayout>

JAVA FILE

package com.example.slip12;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button button;
mytask mytask;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mytask = new mytask();
mytask.execute();
}
});
}
class mytask extends AsyncTask<Void,Integer,Void>{
ProgressDialog manish;
boolean running;
@Override
protected Void doInBackground(Void... Voids){
try {
while (manish.getProgress() <= manish .getMax())
{
Thread.sleep(300);
manish.incrementProgressBy(1);
if(manish.getProgress()==manish.getMax())
{
manish.dismiss();
}
}
}catch(Exception e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
running = true;
manish=new ProgressDialog(MainActivity.this);
manish.setMax(100);
manish.setMessage("loading....................");
manish.setTitle("Progressdialog Box Example");
manish.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
manish.show();
}
@Override
protected void onPostExecute(Void unused) {
super.onPostExecute(unused);
manish.dismiss();
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
manish.setMessage(String.valueOf(values));
}
}
}

You might also like