Tuesday, 3 November 2015
Monday, 5 October 2015
Wednesday, 15 May 2013
All Java Aplet Actions With An Example In A Action programme
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Label;
import java.awt.List;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.concurrent.Executors;
import javax.swing.JButton;
public class action extends Applet implements ActionListener
{
int r, g, b, x, y;
Label l1, l2, l3, l4, l5,l6,l7;
TextField t1, t2, t3, t4, t5, t6,t7,t8;
JButton jb;
Button b1, b2, b3, b4 ,b5, b6, b7, b8,b9,b10,b11,b12,b13,b14,b15;
List L;
public void init()
{
r=g=b=0;
x=800;
y=200;
setLayout(null);
L=new List(5,false);
add(L);
L.add("No. 1");
L.add("No. 2");
L.add("No. 3");
L.add("No. 4");
L.add("No. 5");
L.addActionListener(this);
l5 = new Label("Password");
l1 = new Label("Enter p");
l2 = new Label("Enter r");
l4 = new Label("Enter t");
l3 = new Label("Click On Calculate ");
l6 = new Label("www.");
l7 = new Label(".com");
t1 = new TextField();
t2 = new TextField();
t3 = new TextField();
t4 = new TextField();
t5 = new TextField();
t6 = new TextField();
t7 = new TextField();
t8 = new TextField();
t5.setEchoChar('*');
jb = new JButton("GOOGLE");
b1 = new Button(" Calculate ");
b2 = new Button(" RED ");
b3 = new Button(" Blue ");
b4 = new Button(" Green ");
b5 = new Button("Show");
b6 = new Button("BACKGROUND BRIGHTER");
b7 = new Button("Clockwise");
b8 = new Button("Anticlockwise");
b9 = new Button("Reset");
b10 = new Button("Count");
b11 = new Button("Add");
b12 = new Button("Remove");
b13=new Button("google");
b14=new Button("Notepad");
b15=new Button("GO");
add(jb);
add(b14);
add(t8);
add(b15);
add(l1);
add(t1);
add(l2);
add(t2);
add(l4);
add(l6);
add(l7);
add(t4);
add(l3);
add(b1);
add(t3);
add(b2);
add(b3);
add(b4);
add(l5);
add(t5);
add(b5);
add(t6);
add(b6);
add(b7);
add(b8);
add(b9);
add(b10);
add(b11);
add(b12);
add(t7);
add(b13);
jb.setBounds(800, 30, 100, 20);
b1.setBounds(20,490,100,20);
b2.setBounds(130,490,100,20);
b3.setBounds(240,490,100,20);
b4.setBounds(350,490,100,20);
L.setBounds(10,180,100,100);
l1.setBounds(20,20,100,20);
l2.setBounds(20,50,100,20);
l4.setBounds(20,90,100,20);
l3.setBounds(20,130,100,20);
t1.setBounds(140,20,100,20);
t2.setBounds(140,50,100,20);
t4.setBounds(140,90,100,20);
t3.setBounds(140,130,100,20);
l5.setBounds(500, 20, 100, 20);
t5.setBounds(600, 20, 100, 20);
b5.setBounds(500, 50, 100, 20);
t6.setBounds(600, 50, 100, 20);
b6.setBounds(500, 90, 200, 20);
b8.setBounds(700, 550, 100, 20);
b9.setBounds(800, 550, 100, 20);
b7.setBounds(900, 550, 100, 20);
b10.setBounds(140, 300, 100, 20);
b11.setBounds(140, 330, 100, 20);
b12.setBounds(140, 360, 100, 20);
t7.setBounds(10, 310, 100, 20);
b13.setBounds(400, 20, 100, 20);
b14.setBounds(400, 50, 100, 20);
t8.setBounds(430, 400, 100, 20);
b15.setBounds(710, 400, 20, 20);
l6.setBounds(400, 400, 30, 20);
l7.setBounds(540, 400, 30, 20);
l1.setBackground(Color.RED);
l1.setForeground(Color.BLUE);
l2.setBackground(Color.RED);
l2.setForeground(Color.BLUE);
l3.setBackground(Color.RED);
l3.setForeground(Color.BLUE);
l4.setBackground(Color.RED);
l4.setForeground(Color.BLUE);
b1.setBackground(Color.RED);
b1.setForeground(Color.BLUE);
b2.setBackground(Color.RED);
b3.setBackground(Color.blue);
b4.setBackground(Color.green);
b5.setBackground(Color.green);
b6.setBackground(Color.ORANGE);
b13.setBackground(Color.blue);
//setBackground(Color.yellow);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
jb.addActionListener(this);
// URL u=getDocumentBase();
// Image i=getImage(u, "file:///E:/New%20folder/428817_329971110429317_670594489_n.jpg");
b4.setVisible(false);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int d=Integer.parseInt(t4.getText());
int c=(a*b*d)/100;
String s=String.valueOf(c);
t3.setText(s);
}
if(e.getSource()==b2)
{
setBackground(Color.RED);
b4.setVisible(true);
b2.setVisible(false);
}
if(e.getSource()==b3)
{
setBackground(Color.blue);
b2.setVisible(true);
b4.setVisible(false);
}
if(e.getSource()==b4)
{
setBackground(Color.green);
}
if(e.getSource()==b5)
{
String p=(t5.getText());
t6.setText(p);
}
if(e.getSource()==b6)
{
r=r+10;
g=g+10;
b=b+10;
Color c=new Color(r, g, b);
setBackground(c);
}
if(e.getSource()==b7 && y<=490)
{
x=x+10;
y=y+10;
}
if(e.getSource()==b8 && y<=490)
{
x=x-10;
y=y+10;
}
if(e.getSource()==b9)
{
x=800;
y=200;
}
if(e.getSource()==b10)
{
int c1=L.getItemCount();
String c2=String.valueOf(c1);
t7.setText(c2);
}
if(e.getSource()==b11)
{
String s1=t7.getText();
L.add(s1);
}
if(e.getSource()==b12)
{
String s1=t7.getText();
L.remove(s1);
}
if(e.getSource()==b13)
{
try
{
String[] args = {"cmd","/c","start","www.google.co.in"};
//Runtime rt = Runtime.getRuntime();
//ProcessBuilder pb = new ProcessBuilder(args);
//Process pr = pb.start();
Process p=Runtime.getRuntime().exec(args);
}
catch (Exception ee)
{
System.out.println(ee.getMessage());
}
}
if(e.getSource()==b14)
{
try
{
Process q=Runtime.getRuntime().exec("notepad.exe");
}
catch (Exception ee)
{
System.out.println(ee.getMessage());
}
}
if(e.getSource()==b15)
{
try
{
String s2=t8.getText();
String s3="www."+s2+".com";
String[] args = {"cmd","/c","start",s3};
//Runtime rt = Runtime.getRuntime();
ProcessBuilder pb = new ProcessBuilder(args);
Process pr = pb.start();
}
catch (Exception ee)
{
System.out.println(ee.getMessage());
}
}
if(e.getSource()==jb)
{
try
{
String[] args = {"cmd","/c","start","www.google.co.in"};
//Runtime rt = Runtime.getRuntime();
//ProcessBuilder pb = new ProcessBuilder(args);
//Process pr = pb.start();
Process p=Runtime.getRuntime().exec(args);
}
catch (Exception ee)
{
System.out.println(ee.getMessage());
}
}
repaint();
}
public void paint(Graphics g)
{
if(L.getSelectedIndex()==0)
{
setBackground(Color.yellow);
}
if(L.getSelectedItem()=="No. 2")
{
setBackground(Color.cyan);
}
if(L.getSelectedItem()=="No. 3")
{
setBackground(Color.BLUE);
}
if(L.getSelectedItem()=="No. 4")
{
setBackground(Color.gray);
}
if(L.getSelectedItem()=="No. 5")
{
setBackground(Color.green);
}
URL u=getDocumentBase();
Image i=getImage(u, "file:///E:/New%20folder/428817_329971110429317_670594489_n.jpg");
g.drawImage(i, 0, 0, 1350, 650, this);
g.drawLine(x, y, 800, 500);
}
}
Tuesday, 30 April 2013
marquee applet by sunil kumar dheendhwal
//================================================
// MarqueeApplet.java
// Auto-scrolling and dragging text on the screen
// Yannis Stavrakas, Jan '98
//================================================
import java.awt.*;
import java.applet.Applet;
public class MarqueeApplet extends Applet {
int w, h; //fixed applet width and height
String message;
MarqueeCanvas marquee;
int mouseX;
//standard applet methods
public void init() {
//set html-file-dependent values
w = Integer.parseInt(getParameter("width"));
h = Integer.parseInt(getParameter("height"));
message = getParameter("msg");
setBackground(Color.white);
marquee = new MarqueeCanvas(w, h);
}
public void start() {
setLayout(new BorderLayout());
add("Center", marquee);
marquee.setMsg(message);
marquee.initPos();
marquee.move();
}
public void stop() {
marquee.hold();
remove(marquee);
}
public void destroy() {
}
String[][] parameterInfo = {
{"width", "int", "the applet width"},
{"height", "int", "the applet height"},
{"msg", "String", "the marquee message"}
};
//additional behaviour methods
public boolean handleEvent (Event evt) {
switch (evt.id) {
case Event.MOUSE_DOWN:
mouseX = evt.x;
return true;
case Event.MOUSE_UP: //change scrolling direction
if (evt.x == mouseX) {
marquee.hold();
}
else if (evt.x < mouseX) {
marquee.goLeft(true);
marquee.move();
}
else { //if (evt.x > mouseX)
marquee.goLeft(false);
marquee.move();
}
return true;
}
return super.handleEvent(evt);
}
}
//======================================================
// Marquee msg with scrolling & dragging capabilities
// REDUCED CLASS VERSION FOR MINIMAL APPLET SIZE
//======================================================
class MarqueeCanvas extends Canvas implements Runnable {
//marquee message
boolean isPicture; //marquee message is picture or text?
Image picture;
String text;
Font font;
Color color;
//marquee dimensions
int w;
int h;
//offscreen marquee image
Image im = null;
int imWidth = 0;
int imHeight = 0;
Insets insets = new Insets(2, 2, 2, 2);
//position of image relative to canvas viewport
int viewX = 0;
int viewY = 0;
//mouse X coord while draging
int mouseX;
//thread used as a timer for scrolling image
Thread timerThread = null;
boolean tempStop = false; //class stops thread
boolean stopped = true; //user stops thread
//scrolling parameters
boolean toLeft = true;
int advance = 1;
int interval = 10;
//coords of rectangle to be erased
int dirtyX = 0;
int dirtyY = 0;
int dirtyW = 0;
int dirtyH = 0;
//component readiness to create image
boolean ready = false;
//draw component borders or not
boolean borders = false;
//constructors
public MarqueeCanvas(int w, int h) {
this.w = w;
this.h = h;
//default marquee message attributes
isPicture = false;
picture = null;
text = "";
font = new Font("Helvetica", Font.BOLD, 12);
color = Color.red;
resize(w, h);
}
//marquee message methods
public void setMsg(String text) {
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
dirtyRect(viewX, viewY, imWidth, imHeight);
isPicture = false;
this.picture = null;
this.text = text;
makeImage(this.text);
repaint();
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
}
//scrolling parameter methods
public void goLeft(boolean toLeft) {
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
this.toLeft = toLeft;
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
}
//image positioning methods (relative to canvas)
public void initPos() {
initX();
initY();
}
public void initX() {
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
dirtyRect(viewX, viewY, imWidth, imHeight);
viewX = toLeft? w-1: -(imWidth-1); //to the edge
repaint();
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
}
public void initY() {
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
dirtyRect(viewX, viewY, imWidth, imHeight);
viewY = (int)Math.round((h - imHeight) / 2); //center
repaint();
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
}
//scrolling movement methods
public void move() {
startTimerThread(true);
stopped = false;
}
public void hold() {
startTimerThread(false);
stopped = true;
}
//standard overriden methods
public void paint(Graphics g) {
g.clearRect(dirtyX, dirtyY, dirtyW, dirtyH);
resetDirtyRect();
if (im != null) {
g.drawImage(im, viewX, viewY, this);
}
if (borders) {
g.drawRect(0, 0, w-1, h-1);
}
}
public void update(Graphics g) {
paint(g); //this, with dirtyRect, gives smooth movement
}
public boolean handleEvent (Event evt) {
Component theFrame; //the father of all
switch (evt.id) {
case Event.MOUSE_ENTER:
theFrame = getParent();
while (theFrame.getParent() != null)
theFrame = theFrame.getParent();
((Frame)theFrame).setCursor(Frame.W_RESIZE_CURSOR);
return false; //allow parent to get the message too
case Event.MOUSE_EXIT:
theFrame = getParent();
while (theFrame.getParent() != null)
theFrame = theFrame.getParent();
((Frame)theFrame).setCursor(Frame.DEFAULT_CURSOR);
return false;
case Event.MOUSE_DOWN:
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
mouseX = evt.x;
return false;
case Event.MOUSE_DRAG:
dirtyRect(viewX, viewY, imWidth, imHeight);
viewX += evt.x - mouseX;
mouseX = evt.x;
if (viewX < -(imWidth-1)) viewX = -(imWidth-1);
if (viewX > w-1) viewX = w-1;
repaint();
return false;
case Event.MOUSE_UP:
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
return false;
}
return super.handleEvent(evt);
}
//thread methods
public void run() {
while (timerThread == Thread.currentThread()) {
if (toLeft) {
dirtyRect(viewX+imWidth-advance, viewY, advance, imHeight);
viewX -= advance;
if (viewX < -(imWidth-1)) viewX = w-1;
}
else {
dirtyRect(viewX, viewY, advance, imHeight);
viewX += advance;
if (viewX > w-1) viewX = -(imWidth-1);
}
repaint();
try { Thread.sleep(interval); }
catch (Exception e) {};
}
}
void startTimerThread(boolean start) {
if (start) {
timerThread = new Thread(this);
timerThread.start();
}
else {
timerThread = null;
}
}
//create image with marquee message
void makeImage(String text) {
if ( ! ready) return;
FontMetrics fm = getFontMetrics(font);
imWidth = fm.stringWidth(text) + insets.left + insets.right;
imHeight = fm.getHeight() + insets.top + insets.bottom;
im = createImage(imWidth, imHeight);
Graphics imGraph = im.getGraphics();
imGraph.setColor(color);
imGraph.setFont(font);
int fontDescent = fm.getDescent();
imGraph.drawString(text, insets.left, imHeight-fontDescent-insets.bottom);
if (borders) {
imGraph.drawRect(0, 0, imWidth-1, imHeight-1);
}
imGraph.dispose();
}
//sets coords for dirty rectangle
void dirtyRect(int x, int y, int w, int h) {
//if first call after resetDirtyRect
if (dirtyW == 0 || dirtyH == 0) {
dirtyX = x;
dirtyY = y;
dirtyW = w;
dirtyH = h;
return;
}
//else calculate the bounding rect
int minX = x < dirtyX? x: dirtyX;
int maxX = x+w > dirtyX+dirtyW? x+w: dirtyX+dirtyW;
int minY = y < dirtyY? y: dirtyY;
int maxY = y+h > dirtyY+dirtyH? y+h: dirtyY+dirtyH;
dirtyX = minX;
dirtyY = minY;
dirtyW = maxX - minX;
dirtyH = maxY - minY;
}
void resetDirtyRect() {
dirtyW = 0;
dirtyH = 0;
}
//overriden method, called by system
public void addNotify() {
super.addNotify();
ready = true; //green light to create image
}
}
buffring marquee
import java.applet.*; // involve applet packages
import java.awt.*;
public class Marquee extends Applet {
private Image buffer; // buffer and bufferg are
private Graphics bufferg; // used for double fuffering
private int width; // applet's wodth
private int height; // applet's height
private String text; // text for scrolling
private int x; // aux variable
public void init() { // initialization
text = getParameter("text"); // get text
setBackground(new Color(230,230,130)); // set bgcolor
width = getSize().width; // get applet's width
height = getSize().height; // set applet's height
buffer = createImage(width, height); // create buffers
bufferg = buffer.getGraphics(); // for double buffering
x = width;
}
public void update(Graphics g) { //overwrites standard update
paint(g);
}
public void paint(Graphics g) { // all applet output is here
bufferg.setColor(getBackground()); // set bgcolor
bufferg.fillRect(0, 0, width, height); // clean off-screen buffer
bufferg.setColor(Color.red); // set text color
bufferg.drawString(text, x, 10); // draw text at (x, y)
g.drawImage(buffer, 0, 0, this); // swap the buffers
if (x < -bufferg.getFontMetrics().stringWidth(text))
x = width; // next string position
else // for drawing
x = x - 1;
try {Thread.sleep(30);} // start animation
catch(InterruptedException e){}
repaint(); // update the buffers
}
}
MARQUEE IN JAVA APPLET NEW VERSION
Marquee applet source code
//================================================
// MarqueeApplet.java
// Auto-scrolling and dragging text on the screen
// Yannis Stavrakas, Jan '98
//================================================
import java.awt.*;
import java.applet.Applet;
public class MarqueeApplet extends Applet {
int w, h; //fixed applet width and height
String message;
MarqueeCanvas marquee;
int mouseX;
//standard applet methods
public void init() {
//set html-file-dependent values
w = Integer.parseInt(getParameter("width"));
h = Integer.parseInt(getParameter("height"));
message = getParameter("msg");
setBackground(Color.white);
marquee = new MarqueeCanvas(w, h);
}
public void start() {
setLayout(new BorderLayout());
add("Center", marquee);
marquee.setMsg(message);
marquee.initPos();
marquee.move();
}
public void stop() {
marquee.hold();
remove(marquee);
}
public void destroy() {
}
String[][] parameterInfo = {
{"width", "int", "the applet width"},
{"height", "int", "the applet height"},
{"msg", "String", "the marquee message"}
};
//additional behaviour methods
public boolean handleEvent (Event evt) {
switch (evt.id) {
case Event.MOUSE_DOWN:
mouseX = evt.x;
return true;
case Event.MOUSE_UP: //change scrolling direction
if (evt.x == mouseX) {
marquee.hold();
}
else if (evt.x < mouseX) {
marquee.goLeft(true);
marquee.move();
}
else { //if (evt.x > mouseX)
marquee.goLeft(false);
marquee.move();
}
return true;
}
return super.handleEvent(evt);
}
}
//======================================================
// Marquee msg with scrolling & dragging capabilities
// REDUCED CLASS VERSION FOR MINIMAL APPLET SIZE
//======================================================
class MarqueeCanvas extends Canvas implements Runnable {
//marquee message
boolean isPicture; //marquee message is picture or text?
Image picture;
String text;
Font font;
Color color;
//marquee dimensions
int w;
int h;
//offscreen marquee image
Image im = null;
int imWidth = 0;
int imHeight = 0;
Insets insets = new Insets(2, 2, 2, 2);
//position of image relative to canvas viewport
int viewX = 0;
int viewY = 0;
//mouse X coord while draging
int mouseX;
//thread used as a timer for scrolling image
Thread timerThread = null;
boolean tempStop = false; //class stops thread
boolean stopped = true; //user stops thread
//scrolling parameters
boolean toLeft = true;
int advance = 1;
int interval = 10;
//coords of rectangle to be erased
int dirtyX = 0;
int dirtyY = 0;
int dirtyW = 0;
int dirtyH = 0;
//component readiness to create image
boolean ready = false;
//draw component borders or not
boolean borders = false;
//constructors
public MarqueeCanvas(int w, int h) {
this.w = w;
this.h = h;
//default marquee message attributes
isPicture = false;
picture = null;
text = "";
font = new Font("Helvetica", Font.BOLD, 12);
color = Color.red;
resize(w, h);
}
//marquee message methods
public void setMsg(String text) {
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
dirtyRect(viewX, viewY, imWidth, imHeight);
isPicture = false;
this.picture = null;
this.text = text;
makeImage(this.text);
repaint();
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
}
//scrolling parameter methods
public void goLeft(boolean toLeft) {
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
this.toLeft = toLeft;
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
}
//image positioning methods (relative to canvas)
public void initPos() {
initX();
initY();
}
public void initX() {
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
dirtyRect(viewX, viewY, imWidth, imHeight);
viewX = toLeft? w-1: -(imWidth-1); //to the edge
repaint();
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
}
public void initY() {
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
dirtyRect(viewX, viewY, imWidth, imHeight);
viewY = (int)Math.round((h - imHeight) / 2); //center
repaint();
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
}
//scrolling movement methods
public void move() {
startTimerThread(true);
stopped = false;
}
public void hold() {
startTimerThread(false);
stopped = true;
}
//standard overriden methods
public void paint(Graphics g) {
g.clearRect(dirtyX, dirtyY, dirtyW, dirtyH);
resetDirtyRect();
if (im != null) {
g.drawImage(im, viewX, viewY, this);
}
if (borders) {
g.drawRect(0, 0, w-1, h-1);
}
}
public void update(Graphics g) {
paint(g); //this, with dirtyRect, gives smooth movement
}
public boolean handleEvent (Event evt) {
Component theFrame; //the father of all
switch (evt.id) {
case Event.MOUSE_ENTER:
theFrame = getParent();
while (theFrame.getParent() != null)
theFrame = theFrame.getParent();
((Frame)theFrame).setCursor(Frame.W_RESIZE_CURSOR);
return false; //allow parent to get the message too
case Event.MOUSE_EXIT:
theFrame = getParent();
while (theFrame.getParent() != null)
theFrame = theFrame.getParent();
((Frame)theFrame).setCursor(Frame.DEFAULT_CURSOR);
return false;
case Event.MOUSE_DOWN:
if (timerThread!=null) {
tempStop = true;
startTimerThread(false);
}
mouseX = evt.x;
return false;
case Event.MOUSE_DRAG:
dirtyRect(viewX, viewY, imWidth, imHeight);
viewX += evt.x - mouseX;
mouseX = evt.x;
if (viewX < -(imWidth-1)) viewX = -(imWidth-1);
if (viewX > w-1) viewX = w-1;
repaint();
return false;
case Event.MOUSE_UP:
if (tempStop) {
tempStop = false;
startTimerThread(true);
}
return false;
}
return super.handleEvent(evt);
}
//thread methods
public void run() {
while (timerThread == Thread.currentThread()) {
if (toLeft) {
dirtyRect(viewX+imWidth-advance, viewY, advance, imHeight);
viewX -= advance;
if (viewX < -(imWidth-1)) viewX = w-1;
}
else {
dirtyRect(viewX, viewY, advance, imHeight);
viewX += advance;
if (viewX > w-1) viewX = -(imWidth-1);
}
repaint();
try { Thread.sleep(interval); }
catch (Exception e) {};
}
}
void startTimerThread(boolean start) {
if (start) {
timerThread = new Thread(this);
timerThread.start();
}
else {
timerThread = null;
}
}
//create image with marquee message
void makeImage(String text) {
if ( ! ready) return;
FontMetrics fm = getFontMetrics(font);
imWidth = fm.stringWidth(text) + insets.left + insets.right;
imHeight = fm.getHeight() + insets.top + insets.bottom;
im = createImage(imWidth, imHeight);
Graphics imGraph = im.getGraphics();
imGraph.setColor(color);
imGraph.setFont(font);
int fontDescent = fm.getDescent();
imGraph.drawString(text, insets.left, imHeight-fontDescent-insets.bottom);
if (borders) {
imGraph.drawRect(0, 0, imWidth-1, imHeight-1);
}
imGraph.dispose();
}
//sets coords for dirty rectangle
void dirtyRect(int x, int y, int w, int h) {
//if first call after resetDirtyRect
if (dirtyW == 0 || dirtyH == 0) {
dirtyX = x;
dirtyY = y;
dirtyW = w;
dirtyH = h;
return;
}
//else calculate the bounding rect
int minX = x < dirtyX? x: dirtyX;
int maxX = x+w > dirtyX+dirtyW? x+w: dirtyX+dirtyW;
int minY = y < dirtyY? y: dirtyY;
int maxY = y+h > dirtyY+dirtyH? y+h: dirtyY+dirtyH;
dirtyX = minX;
dirtyY = minY;
dirtyW = maxX - minX;
dirtyH = maxY - minY;
}
void resetDirtyRect() {
dirtyW = 0;
dirtyH = 0;
}
//overriden method, called by system
public void addNotify() {
super.addNotify();
ready = true; //green light to create image
}
}
marquee in java applet
/* import the java.applet class (necessary for all applets) */
import java.applet.*;
/* import the java.awt (Abstract Windows Toolkit) classes */
import java.awt.*;
/* declare a class Marquee that can use all variables and functions
from the Applet class. The Runnable interface is needed to
provide functions that will allow for the execution of the
applet; the Runnable function used here is run(). */
public class Marquee extends Applet implements Runnable {
/* define a Thread, t. Think of a Thread as a process; it can be
started and stopped as necessary within the code. */
Thread t;
/* define a String, msg, to hold the text we wish to scroll */
String msg = "Welcome to the Wonderful World of JAVA!";
/* define an integer, msgWidth, to hold the length of the string
in pixels. */
int msgWidth;
/* define an integer, pos, to hold the current X position of the
text. */
int pos;
/* define an integer, yLoc, to hold the Y position of the text. */
int yLoc = 15;
/* init is the first function called in a Java applet. */
public void init()
{
/* resize the applet window to 400x20 */
resize(400, 20);
/* set the Background color of the applet to white in the form
(Red, Green, Blue) with integer values ranging from 0-255. */
setBackground(new Color(255, 255, 255));
/* use the getFontMetrics function to get the width of the
string, in pixels. */
msgWidth = getFontMetrics(getFont()).stringWidth(msg);
/* set the intital position of the text to the right side of
the applet window. */
pos = size().width;
/* set t to be a new Thread within 'this,' the Marquee class. */
t = new Thread(this);
/* start the thread. This calls the run() function. */
t.start();
}
/* the paint function is called whenever the window needs
to be updated; the repaint() statement also calls this
function. Here, we use it to draw the msg string at
the coordinates specified by the pos and yLoc variables. */
public void paint(Graphics g)
{
g.drawString(msg, pos, yLoc);
}
/* t.start() calls the run() function. Here, the while loop
will iterate continuously; each iteration will repaint the
applet (drawing the string five pixels to the left of its
previous location), and pause for 100 milliseconds. If the
complete string has scrolled off to the left side of the applet
window (pos <= -msgWidth), reposition the string to the
right side of the applet window. */
public void run()
{
while(true)
{
repaint();
pos -= 5;
try
{
t.sleep(100);
}
catch(Exception e)
{
}
if (pos <= -msgWidth)
{
pos = size().width;
}
}
}
}
Monday, 8 April 2013
Bring a Image In Java Applet Programme
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.net.URL;
public class im1 extends Applet
{
/**
*
*/
private static final long serialVersionUID = 1L;
public void paint(Graphics g)
{
URL u=getDocumentBase();
Image i=getImage(u, "freedocru476121280x1024to5.jpg ");
g.drawImage(i, 10, 10, 200, 300, this);
}
}
MAKE ANY APPLET LAYOUT
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="layout.java" width=500 height=500>
</applet>
*/
public class layout extends Applet implements ActionListener
{
Button b1,b2,b3,b4,b5,b6,b7,b8;
public void init()
{
setLayout(new FlowLayout(FlowLayout.CENTER));
b1=new Button("red");
b2=new Button("cyan");
b3=new Button("pink");
b4=new Button("yellow");
b5=new Button("magenta");
b6=new Button("black");
b7=new Button("blue");
b8=new Button("orange");
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
if(s.equals("red"))
setBackground(Color.red);
if(s.equals("cyan"))
setBackground(Color.cyan);
if(s.equals("pink"))
setBackground(Color.pink);
if(s.equals("yellow"))
setBackground(Color.yellow);
if(s.equals("magenta"))
setBackground(Color.magenta);
if(s.equals("black"))
setBackground(Color.black);
if(s.equals("blue"))
setBackground(Color.blue);
if(s.equals("orange"))
setBackground(Color.orange);
repaint();
}
}
Monday, 1 April 2013
How to find some of digits of any given number
How to find some of digits of any given number
import java.util.*;
class A
{
int a,n,b,z,c=0;
void get()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter any number ");
n=sc.nextInt();
z=n;
}
void put()
{
while(n!=0)
{
a=n%10;
b=n/10;
n=b;
c=c+a;
}
System.out.print("number is "+z+"sum of all digits is "+c);
}
public static void main(String[] args)
{
A a=new A();
a.get();
a.put();
}}
import java.util.*;
class A
{
int a,n,b,z,c=0;
void get()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter any number ");
n=sc.nextInt();
z=n;
}
void put()
{
while(n!=0)
{
a=n%10;
b=n/10;
n=b;
c=c+a;
}
System.out.print("number is "+z+"sum of all digits is "+c);
}
public static void main(String[] args)
{
A a=new A();
a.get();
a.put();
}}
Fectorial of a number in java
Fectorial of a number
import java.util.*;class A
{
int a,i,f=1;
void get()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Value of a ");
a=sc.nextInt();
}
void put()
{
for(i=1;i<=a;i++)
{
f=f*i;
}
System.out.print("Fectorial Of "+a+" is "+f);
}
public static void main(String[] args)
{
A a=new A();
a.get();
a.put();
}}
How to find some of three numbers in java
find three numbers sum
import java.util.*;
class A
{
int a,b,c,d;
void get()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Value of a ");
a=sc.nextInt();
System.out.print("Enter the Value of b ");
b=sc.nextInt();
System.out.print("Enter the Value of c ");
c=sc.nextInt();
}
void put()
{
d=a+b+c;
System.out.print("Sum Of a+b+c is = "+d);
}
public static void main(String[] args)
{
A a=new A();
a.get();
a.put();
}}
SIMPLE PROGRAMME OF JAVA
import java.util.*;
class A
{
int i;
void hello()
{
for(i=1;i<=5;i++)
{
System.out.print("======");
}
}
public static void main(String[] args)
{
A a=new A();
a.hello();
System.out.print("\nHello\n");
a.hello();
System.out.print("\nWELCOME TO SESSION OF JAVA\n");
a.hello();
System.out.print("\nHAVE A NICE SESSION\n");
a.hello();
System.out.print("\nSUCCESSFUL\n");
a.hello();
System.out.print("\nSUCCESSFUL SUCCESSFUL\n");
a.hello();
System.out.print("\nHAVE A NICE YEAR\n");
a.hello();
System.out.print("\nHAVE A NICE DAY\n");
a.hello();
System.out.print("\nLEARN JAVA CAREFULLY\n");
a.hello();
System.out.print("\nBE CAREFULL\n");
a.hello();
System.out.print("\nWELCOME TO HAVEN WORLD\n");
a.hello();
System.out.print("\nHOPE YOU ENJOY\n");
a.hello();
System.out.print("\nTHANK YOU\n");
a.hello();
}}
Sunday, 31 March 2013
DEFINATION OF SOME JAVA CLASSES
If this is your first encounter with object-oriented programming, a lot of the information in this lesson is going to seem really theoretical and overwhelming. Fear not-the further along in this book you get, and the more Java classes and applications you create, the easier it is to understand.
One of the biggest hurdles of object-oriented programming is not necessarily the concepts; it's their names. OOP has lots of jargon surrounding it. To summarize today's material, here's a glossary of terms and concepts you learned today:
class:
A template for an object, which contains variables and methods representing behavior and attributes. Classes can inherit variables and methods from other classes.
class method:
A method defined in a class, which operates on the class itself and can be called via the class or any of its instances.
class variable:A variable that is "owned" by the class and all its instances as a whole and is stored in the class.
class variable:A variable that is "owned" by the class and all its instances as a whole and is stored in the class.
instance:
The same thing as an object; each object is an instance of some class.
instance method:
A method defined in a class, which operates on an instance of that class. Instance methods are usually called just methods.
instance variable:
A variable that is owned by an individual instance and whose value is stored in the instance.
interface:
A collection of abstract behavior specifications that individual classes can then implement.
object:
A concrete instance of some class. Multiple objects that are instances of the same class have access to the same methods, but often have different values for their instance variables.
package:
A collection of classes and interfaces. Classes from packages other than java.lang must be explicitly imported or referred to by full package name.
subclass:
A class lower in the inheritance hierarchy than its parent, the superclass. When you create a new class, it's often called subclassing.
superclass:
A class further up in the inheritance hierarchy than its child, the subclass.
Java's Future And why Learn Java??
What's in store for Java in the future? A number of new developments have been brewing (pardon the pun):
- Sun is developing a number of new features for the Java environment, including a number of new class libraries for database integration, multimedia, electronic commerce, and other uses. Sun also has a Java-based Web server, a Java-based hardware chip (with which you can write Java-specific systems), and a Java-based operating system. You'll learn about all these things later in this book. The 1.1 release of the JDK will include many of these features; others will be released as separate packages.
- Sun is also developing a framework called Java Beans, which will allow the development of component objects in Java, similarly to Microsoft's ActiveX (OLE) tech-nology. These different components can then be easily combined and interact with each other using standard component assembly tools. You'll learn more about Java Beans later in this book.
- Java capabilities will be incorporated into a wide variety of operating systems, including Solaris, Windows 95, and MacOS. This means that Java applications (as opposed to applets) can run nearly anywhere without needing additional software to be installed.
- Many companies are working on performance enhancements for Java programs, including the aforementioned Java chip and what are called just-in-time compilers.
Why Learn Java?
At the moment, probably the most compelling reason to learn Java-and probably the reason you bought this book-is that applets are written in Java. Even if that were not the case, Java as a programming language has significant advantages over other languages and other environments that make it suitable for just about any programming task. This section describes some of those advantages.Java Is Platform Independent
Platform independence-that is, the ability of a program to move easily from one computer system to another-is one of the most significant advantages that Java has over other programming languages, particularly if your software needs to run on many different platforms. If you're writing software for the World Wide Web, being able to run the same program on many different systems is crucial to that program's success. Java is platform independent at both the source and the binary level.Java Is Object Oriented
To some, the object-oriented programming (OOP) technique is merely a way of organizing programs, and it can be accomplished using any language. Working with a real object-oriented language and programming environment, however, enables you to take full advantage of object-oriented methodology and its capabilities for creating flexible, modular programs and reusing code.Java Is Easy to Learn
In addition to its portability and object orientation, one of Java's initial design goals was to be small and simple, and therefore easier to write, easier to compile, easier to debug, and, best of all, easy to learn. Keeping the language small also makes it more robust because there are fewer chances for programmers to make mistakes that are difficult to fix. Despite its size and simple design, however, Java still has a great deal of power and flexibility.WHAT IS JAVA ????
Based on the enormous amount of press Java is getting and the amount
of excitement it has generated, you may get the impression that Java will
save the world-or at least solve all the problems of the Internet. Not so.
Java's hype has run far ahead of its capabilities, and while Java is indeed
new and interesting, it really is another programming language with which
you write programs that run on the Internet. In this respect, Java is closer
to popular programming languages such as C, C++, Visual Basic, or Pascal,
than it is to a page description language such as HTML,
or a very simple scripting language such as JavaScript.
More specifically, Java is an object-oriented programming language developed
by Sun Microsystems, a company best known for its high-end UNIX workstations.
Modeled after C++, the Java language was designed to be small, simple, and
portable across platforms and operating systems, both at the source and at the
binary level, which means that Java programs (applets and applications) can run
on any machine that has the Java virtual machine installed (you'll learn more about this later).
Java is usually mentioned in the context of the World Wide Web, where browsers
such as Netscape's Navigator and Microsoft's Internet Explorer claim to be "Java enabled."
Java enabled means that the browser in question can download and play Java programs,
called applets, on the reader's system. Applets appear in a Web page much the same way
as images do, but unlike images, applets are dynamic and interactive. Applets can be used
to create animation, figures, forms that immediately respond to input from the reader, games,
or other interactive effects on the same Web pages among the text and graphics.
Saturday, 30 March 2013
WEL_COME to java Universe
Hey Dear Welcome To Java World
Here we made this blog to improve your knowledge about
java programming and help to improve your
computer programming knowledge.......................
Here we are specially going to help our those friends who
have troubles in programming.............................
In this blog we started with basic Knowledge to Upgredetion so
that you can learn Programming very easily..............................
-- SUNIL KUMAR MUKESH KUMAR
java programming and help to improve your
computer programming knowledge.......................
have troubles in programming.............................
that you can learn Programming very easily..............................
-- SUNIL KUMAR MUKESH KUMAR
Subscribe to:
Posts (Atom)


