- 1
Any one set this output to textarea
import java.awt.Button; import java.awt.Component; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Frame; import java.awt.GridLayout; import java.awt.Panel; import java.awt.TextArea; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; class Gui22 extends WindowAdapter implements ActionListener{ Frame f; Button b1; TextArea tfa; int n1; Panel p;
1 Answer
0
import java.awt.Button;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class Gui22 extends WindowAdapter implements ActionListener{
Frame f;
Button b1;
TextArea tfa;
int n1;
Panel p;
Gui22(){
f=new Frame("tower of hanoi");
f.setLayout(new GridLayout(2,0));
f.setSize(300,300);
f.show();
p =new Panel();
p.setLayout(new GridLayout(2,2));
sb=new StringBuilder();
b1=new Button("continu");
tfa=new TextArea(" ");
tfa.setFont (new Font("Helvetica", Font.BOLD, 18));
tfa.setEditable (true);
tfa.setSize(70,100 );
p.add(b1);
f.add(tfa);
f.addWindowListener(this);
b1.addActionListener(this);
}
public void windowClosing(WindowEvent we){
System.exit(0);
}
private String s;
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==b1){
move(3,1,3);
}
}
void move(int n, int startPole, int endPole) {
if (n== 0) {
return;
}
int intermediatePole = 6 - startPole - endPole;
move(n-1, startPole, intermediatePole);
System.out.println("Move " +n + " from " + startPole + " to " +endPole+"\n");
move(n-1, intermediatePole, endPole);
}
}
public class JavaApplication20 {
public static void main(String[] args) {
Gui22 gu=new Gui22();
}
}