0
How can we display the output of function on JTextArea in java ?
i want to display on JTextArea please only on help public static 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); move(n-1, intermediatePole, endPole); }
6 ответов
+ 5
after
tfa.setSize(70,100);
add:
tfa.setText("your text goes here");
or, in case it's not working, replace it with:
tfa.append("your text goes here");
+ 4
yourJTextArea.setText("whatever you want to write goes in here");
https://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html
https://docs.oracle.com/javase/8/docs/api/javax/swing/text/JTextComponent.html#setText-java.lang.String-
0
i can't understand
0
can wo please guide me
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();
}
}
0
its my code bro can you set this out put to my TextArea