Sunday, 5 October 2014

Details form

Simple form to enter details. I wouldn't really recommend this. Use a box layout or use panels. But this will suffice for small purposes.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class det extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4;
JTextField t1,t2,t3,t4;
JButton l5;
JTextArea jt;
det()
{
JFrame jf=new JFrame();
jt=new JTextArea();
jt.setBounds(200,200,150,150);
l5=new JButton("SUBMIT");
l5.setBounds(10,210,100,60);
l1=new JLabel("Name");
l1.setBounds(10,10,50,50);
t1=new JTextField("");
t1.setBounds(70,30,70,20);
l2=new JLabel("Age");
l2.setBounds(10,70,50,50);
t2=new JTextField("");
t2.setBounds(70,90,70,20);
l3=new JLabel("Branch");
l3.setBounds(10,120,50,50);
t3=new JTextField("");
t3.setBounds(70,140,70,20);
l4=new JLabel("Mark");
l4.setBounds(10,160,50,50);
t4=new JTextField("");
t4.setBounds(70,180,70,20);
jf.setLayout(null);
jf.add(l1);
jf.add(l2);
jf.add(l3);
jf.add(l4);
jf.add(t1);
jf.add(t2);
jf.add(t3);
jf.add(t4);
jf.add(jt);
l5.addActionListener(this);
jf.add(l5);


jf.setSize(500,500);
jf.setVisible(true);
}
public static void main(String args[])
{
det x=new det();
}

public void actionPerformed(ActionEvent ae)
{
jt.setText(t1.getText()+"\n");
jt.append(t2.getText()+"\n");
jt.append(t3.getText()+"\n");
jt.append(t4.getText()+"\n");
}
}

Saturday, 4 October 2014

Paint a house

Simplet applet to draw a house. Use appletviewer

import java.applet.*;
import java.awt.*;
import java.io.*;
//<applet code="struct" width=500 height=500>
//</applet>
public class struct extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.orange);
g.fillRect(50,100,100,50);
int x[]={50,100,150};
int y[]={100,50,100};
g.setColor(Color.black);
g.drawPolygon(x,y,3);
g.fillPolygon(x,y,3);
g.setColor(Color.blue);
g.fillRect(60,110,20,20);
g.fillRect(110,110,20,20);
g.setColor(Color.green);
g.fillRect(85,125,20,25);

}
}

Indian Flag

This is a program to paint the Indian Flag. Use appletviewer

import java.io.*;
import java.applet.*;
import java.awt.*;
//<applet code="iflag" height=500 width=500>
//</applet>
public class iflag extends Applet
{
public void paint(Graphics g)
{

g.setColor(Color.orange);
g.fillRect(0,0,100,25);

g.setColor(Color.white);
g.fillRect(0,25,100,25);
g.setColor(Color.black);
g.fillRect(100,0,10,500);
g.setColor(Color.green);
g.fillRect(0,50,100,25);
g.setColor(Color.blue);
g.drawOval(35,25,25,25);
int x=48,y=39;
double r=12.5,x1,y1,d=0,t=0;
for(int i=1;i<=24;i++)
{
d=t*3.14/180;
x1=x+r*Math.cos(d);
y1=y+r*Math.sin(d);
g.drawLine(x,y,(int)x1,(int)y1);
t=t+360/24;
}
}
}