Posts

Showing posts from June 1, 2014

Make pattern in swing with package

Image
package work;

import java.io.*;

public class pack1
{

public static String make(int n)
{
String s="";
int i,j,k;
for(i=0; i<n;i++)
{
for(k=n-i-1;k>=0;k--)
s=s+" ";

for(j=0;j<=i*2+1;j++)
s=s+"*";
s+="\n";
}
return s;


}
}




import java.applet.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.lang.*;
import work.pack1;

public class a2 implements ActionListener
{
JButton b1,b2;
JFrame jf;
JTextArea jta;
JScrollPane  jsp;
JTextField jtf;
JToolBar jtb;
a2()
{
frame();
button();
text();
jf.setVisible(true);
tool();

}

public void button()
{
b1=new JButton("pattern");
b2=new JButton("clear");
b1.addActionListener(this);
b2.addActionListener(this);
}
public void tool()
{
jtb=new JToolBar();

jtb.add(b1);
jtb.add(b2);
jtb.add(jtf);
jf.add(jtb,BorderLayout.NORTH);

}

public void frame()
{
jf=new JFrame(" pattern maker");
jf.setSize(100,300);
}
pub…