






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
some java applet programs and c programs
Typology: Exercises
1 / 12
This page cannot be seen from the preview
Don't miss anything!
import java.applet.Applet; import java.awt.; import java.awt.event.; // public class Appletsum extends Applet implements ActionListener { Button b1,b2; TextField t1,t2,t3,t4,t5; Label l1,l2,l3,l4,l5,l6,l7;
public void init(){
l1= new Label("Name of a student "); l2= new Label("Marks is Subject 1"); l3= new Label("Marks is Subject 2"); l4= new Label("Marks is Subject 3"); l5= new Label("Marks is Subject 4"); l6= new Label(); l7= new Label(); t1= new TextField(); t2= new TextField(); t3= new TextField(); t4= new TextField(); t5= new TextField(); b1= new Button("SUM"); b2= new Button("AVG"); setLayout(null); l1.setBounds(30,30,100,30); l2.setBounds(30,60,100,30); l3.setBounds(30,90,100,30); l4.setBounds(30,120,100,30); l5.setBounds(30,150,100,30);
t1.setBounds(200,30,100,30); t2.setBounds(200,60,100,30); t3.setBounds(200,90,100,30); t4.setBounds(200,120,100,30); t5.setBounds(200,150,100,30); b1.setBounds(60,200,100,30); b2.setBounds(60,250,100,30);
l6.setBounds(200,200,100,30); l7.setBounds(200,250,100,30);
add(l1); add(l2); add(l3); add(l4); add(l5); add(t1); add(t2); add(t3); add(t4); add(t5); add(b1); add(b2); add(l6); add(l7); b1.addActionListener( this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e){ int a,b,c,d,s; float avg; String x; a=Integer.parseInt(t2.getText()); b=Integer.parseInt(t3.getText()); c=Integer.parseInt(t4.getText()); d=Integer.parseInt(t5.getText());
s=a+b+c+d; avg= (a+b+c+d)/4; l6.setText("sum is "+s); l7.setText("Average"+avg); }
public void mouseExited(MouseEvent me) { mousex=0; mousey=10; msg="mouse exited"; repaint(); }
public void mousePressed(MouseEvent me) { mousex=me.getX(); mousey=me.getY(); msg="down"; repaint(); }
public void mouseReleased(MouseEvent me) { mousex=me.getX(); mousey=me.getY(); msg="up"; repaint(); }
public void mouseDragged(MouseEvent me) { mousex=me.getX(); mousey=me.getY(); msg="*"; showStatus("Dragging mouse at "+mousex+" , "+mousey); repaint(); }
public void mouseMoved(MouseEvent me) { showStatus("mouse moving at "+me.getX()+" , "+me.getY()); } public void paint(Graphics g) { g.drawString(msg,mousex,mousey); } }
import java.awt.; import java.awt.event.; import java.applet.; / */ public class KeyE extends Applet implements KeyListener { String msg = ""; int X = 10, Y = 20; public void init() { addKeyListener(this); }
public void keyPressed(KeyEvent ke) { showStatus("Key Down"); }
public void keyReleased(KeyEvent ke) { showStatus("Key Up"); }
public void keyTyped(KeyEvent ke) { msg += ke.getKeyChar(); repaint(); }
public void paint(Graphics g) { g.drawString(msg, X, Y); } }
t1=new TextField(3); p4.add(t1); p4.add(new Label(" MARKS IN SUBJECT 2.")); t2=new TextField(3); p4.add(t2); p4.add(new Label(" MARKS IN SUBJECT 3.")); t3=new TextField(3); p4.add(t3); p4.add(new Label(" MARKS IN SUBJECT 4.")); t4=new TextField(3); p4.add(t4); p4.add(new Label("TOTAL")); t5=new TextField(3); p4.add(t5); p4.add(new Label("AVERAGE")); t6=new TextField(3); p4.add(t6); p4.add(tot); p4.add(avg); add(p4); m.addItemListener(this); f.addItemListener(this); c1.addItemListener(this); c2.addItemListener(this); tot.addActionListener(this); avg.addActionListener(this); } public void paint(Graphics g) { int m1,m2,m3,m4,tot; float avg=0.0f; m1=m2=m3=m4=tot=0; m1=Integer.parseInt(t1.getText()); m2=Integer.parseInt(t2.getText()); m3=Integer.parseInt(t3.getText()); m4=Integer.parseInt(t4.getText()); tot=m1+m2+m3+m4; avg=tot/4; s1=String.valueOf(tot); s2=String.valueOf(avg); s3=""; } public void actionPerformed(ActionEvent e) { s3=e.getActionCommand(); if(s3.equals("TOTAL")) t5.setText(s1); if(s3.equals("AVERAGE")) t6.setText(s2); repaint(); } public void itemStateChanged(ItemEvent e) { repaint(); } }
import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays;
public class IPAddress { public static void main(String args[]) { InetAddress myIP = null; try { myIP = InetAddress.getLocalHost();
String IPAddress = myIP.getHostAddress(); String hostname = myIP.getHostName(); System.out.printf("IP address of Localhost is %s %n", IPAddress); System.out.printf("Host name of your machine is %s %n", hostname); } catch(Exception e){System.out.println(e);}
import java.io.; import java.net.; public class URLDemo { public static void main(String[] args){ try{ URL url=new URL("http://www.facebook.com");
System.out.print((char) c); } input.close(); } else { System.out.println("No Content Available"); } } }
S.No Title P.No Reamks