Pages

Labels In Advance Java... Use of label....

import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.text.StyledEditorKit.BoldAction;


public class label1  extends JApplet{
private static final int BoldAction = 0;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15;
@Override
public void init() {

l1=new JLabel(new ImageIcon("D:\\IMAGES & PICS\\1501805_230076137169349_491470829_n.jpg"),JLabel.RIGHT);
setLayout(null);
l1.setBounds(20,150,550,700);
l1.setToolTipText("Image of Books");
add(l1);
l1.setBorder(BorderFactory.createBevelBorder(0));

l2=new JLabel(new String("<=== Programming Books"),JLabel.CENTER);
l2.setBounds(570,275,160,60);
l2.setToolTipText("Programming Books");
l2.setForeground(Color.RED);
add(l2);
//l2.setBorder(BorderFactory.createBevelBorder(0));

l3=new JLabel(new String("WElcome to Advance Java............"), new ImageIcon("D:\\advance java.JPG"),JLabel.RIGHT);
setLayout(null);
l3.setBounds(20,5,1300,150);
l3.setForeground(Color.GREEN);
l3.setFont(new Font("Monotype Corsiva", BoldAction, 70));
l3.setIconTextGap(30);
add(l3);
l3.setBorder(BorderFactory.createBevelBorder(0));

l4=new JLabel(new String("Right Text   "),JLabel.RIGHT);
l4.setBounds(750,160,300,50);
l4.setForeground(Color.GREEN);
add(l4);
l4.setBorder(BorderFactory.createBevelBorder(0));

l5=new JLabel(new String("Center Text"),JLabel.CENTER);
l5.setBounds(750,210,300,50);
l5.setForeground(Color.RED);
add(l5);
l5.setBorder(BorderFactory.createBevelBorder(0));


l6=new JLabel(new String("  Left Text"),JLabel.LEFT);
l6.setBounds(750,260,300,50);
l6.setForeground(Color.BLUE);
add(l6);
l6.setBorder(BorderFactory.createBevelBorder(0));

l7=new JLabel(new String("Top Center Text"),JLabel.CENTER);
l7.setBounds(750,310,300,50);
l7.setForeground(Color.GREEN);
l7.setVerticalAlignment(JLabel.TOP);
add(l7);
l7.setBorder(BorderFactory.createBevelBorder(0));

l8=new JLabel(new String("Center Center Text"),JLabel.CENTER);
l8.setBounds(750,360,300,50);
l8.setForeground(Color.RED);
l8.setVerticalAlignment(JLabel.CENTER);
add(l8);
l8.setBorder(BorderFactory.createBevelBorder(0));

l9=new JLabel(new String("Bottom Center Text"),JLabel.CENTER);
l9.setBounds(750,410,300,50);
l9.setForeground(Color.BLUE);
l9.setVerticalAlignment(JLabel.BOTTOM);
add(l9);
l9.setBorder(BorderFactory.createBevelBorder(0));

l10=new JLabel(new String("  Center Left Text"),JLabel.LEFT);
l10.setBounds(750,460,300,50);
l10.setForeground(Color.GREEN);
l10.setVerticalAlignment(JLabel.CENTER);
add(l10);
l10.setBorder(BorderFactory.createBevelBorder(0));

l11=new JLabel(new String("Center Right Text  "),JLabel.RIGHT);
l11.setBounds(1050,460,300,50);
l11.setForeground(Color.RED);
l11.setVerticalAlignment(JLabel.CENTER);
add(l11);
l11.setBorder(BorderFactory.createBevelBorder(0));

l12=new JLabel(new String("  Bottom Left Text"),JLabel.LEFT);
l12.setBounds(750,510,300,50);
l12.setForeground(Color.BLUE);
l12.setVerticalAlignment(JLabel.BOTTOM);
add(l12);
l12.setBorder(BorderFactory.createBevelBorder(0));

l13=new JLabel(new String("Bottom Right Text  "),JLabel.RIGHT);
l13.setBounds(1050,510,300,50);
l13.setForeground(Color.GREEN);
l13.setVerticalAlignment(JLabel.BOTTOM);
add(l13);
l13.setBorder(BorderFactory.createBevelBorder(0));

l14=new JLabel(new String("Top Right Text  "),JLabel.RIGHT);
l14.setBounds(750,560,300,50);
l14.setForeground(Color.RED);
l14.setVerticalAlignment(JLabel.TOP);
add(l14);
l14.setBorder(BorderFactory.createBevelBorder(0));

l15=new JLabel(new String("  Top Left Text"),JLabel.LEFT);
l15.setBounds(1050,560,300,50);
l15.setForeground(Color.BLUE);
l15.setVerticalAlignment(JLabel.TOP);
add(l15);
l15.setBorder(BorderFactory.createBevelBorder(0));
}

}


Text Field In Advance Java.... Text Field use in java...

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


public class textfield1 extends JApplet implements FocusListener,ActionListener{
 static final int BoldAction = 0;
JTextField t1,t2,t3,t4,t5,t6,t7;
JButton b1,b2;

public void init(){

t1=new JTextField("hello");
add(t1);
setLayout(null);
t1.setBounds(30,30,100,30);
t1.selectAll();
t1.setSelectionColor(Color.red);

t1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
t1.setBackground(Color.cyan);
}
}
);
t2=new JTextField(20);
add(t2);
setLayout(null);
t2.setBounds(140,30,170,30);
t2.selectAll();
t2.setSelectionColor(Color.BLUE);
t2.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
t2.setText("Yes You Clicked On Enter");

}
});

t3=new JTextField("Words Entered Already");
add(t3);
setLayout(null);
t3.setBounds(330,30,500,30);
t3.selectAll();
t3.setSelectionColor(Color.BLUE);
t3.setHorizontalAlignment(JTextField.LEFT);
t3.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
t3.setText("Words Entered Already Thanx For Click Again");
if(t3.getHorizontalAlignment()==JTextField.LEFT)
t3.setHorizontalAlignment(JTextField.CENTER);
else if(t3.getHorizontalAlignment()==JTextField.CENTER)
t3.setHorizontalAlignment(JTextField.RIGHT);
else if(t3.getHorizontalAlignment()==JTextField.RIGHT)
t3.setHorizontalAlignment(JTextField.LEFT);

}
});



t4=new JTextField("When you click on enter Thil text will hide");
add(t4);
setLayout(null);
t4.setBounds(630,90,500,30);
t4.selectAll();
t4.setSelectionColor(Color.RED);
t4.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
t4.setText("");

}
});

t5=new JTextField("Enter First name");
t6=new JTextField("Enter Last name");
add(t5);
add(t6);
setLayout(null);
t5.setBounds(40,160,500,30);
t6.setBounds(40,200,500,30);
t5.selectAll();
t6.selectAll();
t5.setSelectionColor(Color.cyan);
t6.setSelectionColor(Color.cyan);

t5.addFocusListener(this);
t6.addFocusListener(this);

t7=new JTextField("Click here for type");
add(t7);
setLayout(null);
t7.setBounds(530,330,500,30);
t7.selectAll();
t7.setSelectionColor(Color.RED);
b1=new JButton("Int");
b2=new JButton("Char");
add(b1);
add(b2);
b1.setBounds(530, 380, 100, 30);
b2.setBounds(650, 380, 100, 30);
b1.addActionListener(this);
b2.addActionListener(this);

}

public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource()==t5)
{
t6.setText("Lname");
t5.selectAll();
}
else if(arg0.getSource()==t6)
{
t5.setText("Fname");
t6.selectAll();
}
}

@Override
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
t5.setText("Now Type here For Enter First Name");
t6.setText("Now Type here For Enter Last Name");
}

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==b1)
{
JOptionPane.showMessageDialog(null, "Please Enter numeric values");
}
if(e.getSource()==b2)
{
JOptionPane.showMessageDialog(null, "Please Enter Char Values");
}

}

}



Graphics Codding In Core Java or in advance Java...

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;


public class graphicsdata extends Applet
{
public void init()
{
setBackground(Color.BLACK);
setForeground(Color.WHITE);
}
public void paint(Graphics g)
{
int i;
g.drawLine(10, 10, 700, 10);
g.drawString("Single LINE",710, 10 );

g.drawRect(10, 20, 35, 35);
g.fillRect(120, 20, 35, 35);
g.drawString("<--Rect-->",55 ,40 );

g.drawOval(10, 60, 60, 60);
g.fillOval(120, 60, 60, 60);
g.drawString("Circles", 80, 80);

g.drawArc(10, 125, 60, 60, 90, 270);
g.fillArc(120, 125,60 , 60, 90, 270);
g.drawString("Arcs", 80, 140);

int x[]={60,110,110,10,10};
int y[]={200,250,300,300,250};
int n=5;
int a[]={170,220,220,120,120};
int b[]={200,250,300,300,250};
int c=5;
g.drawPolygon(x,y, n);
g.fillPolygon(a,b,c);
g.drawString("Polygon", 50, 260);

g.drawLine(10,320,10,400);
g.drawLine(100, 320, 100, 400);
g.drawOval(10, 316, 90, 10);
g.drawOval(10, 396, 90, 10);
g.drawString("<----CYLINDER", 120, 350);

g.drawLine(50, 420, 00, 550);
g.drawLine(50, 420, 100, 550);
g.drawOval(00, 546, 100, 10);
g.drawString("<----Cone", 120, 470);



g.drawOval(300, 100, 100, 100);
g.drawOval(325, 125, 50, 50);
g.drawRect(280, 80, 140, 140);
g.drawOval(240, 40, 220, 220);
g.drawOval(500, 40, 220, 220);
g.drawArc(560, 140, 100, 70, 215, 115);
g.drawOval(540, 100, 50, 20);
g.drawOval(630, 100, 50, 20);
g.drawLine(600, 110, 595, 180);
g.drawLine(620, 110, 625, 180);
g.drawLine(595,180,625,180);
g.drawArc(485, 110, 70, 70, 110, 130);
g.drawArc(665, 110, 70, 70, 70, -130);
g.drawString("HUMAN FACE", 570, 300);


g.drawRect(400, 350, 200, 200);
g.drawRect(440, 390, 200, 200);
g.drawLine(400, 350, 440, 390);
g.drawLine(600, 550, 640, 590);
g.drawLine(600, 350, 640, 390);
g.drawLine(400, 550, 440, 590);
g.drawString("CUBE",480, 480);

g.drawRoundRect(750, 30, 200, 200, 70, 70);
g.fillRoundRect(750, 300, 200, 200, 70, 70);
g.drawString("Round Rect", 820, 150);

g.drawLine(1000, 20, 1000, 200);
g.drawLine(1000, 200, 1300, 200);
g.drawLine(1000, 200, 1050, 150);
g.drawLine(1050, 150, 1090, 150);
g.drawLine(1090, 150, 1150, 120);
g.drawLine(1150, 120, 1200, 150);
g.drawLine(1200, 150, 1250, 100);
g.drawString("----------Line Graph-----------", 1100, 230);


g.fillArc(1000, 300, 200, 200, 00, 30);
g.fillArc(1000, 300, 200, 200, 90, 30);
g.fillArc(1000, 300, 200, 200, 180, 30);
g.fillArc(1000, 300, 200, 200, 270, 30);
g.drawString("FAN", 1050, 470);

}
}

Largest Programme Of Core Java....


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);
}
}