Witam,
mam problem ze zmianą tekstu po naciśnięciu przycisku. JTextArea posiada swoją klasę, natomiast przycisk znajduje się w innej klasie.
oto kod klasy z JTextArea
package DisplayWindow;
import java.awt.TextArea;
import java.io.File;
import java.util.Scanner;
@SuppressWarnings("serial")
public class InformationLayout extends TextArea {
static Scanner scan;
static String line;
static String information = "";
public InformationLayout(){
if (ObjectLayout.object.equals("czaszka"))
new InformationLayout();
//this.replaceSelection(load());
//this.insert(load(), 5);
this.setText("load()");
if (ObjectLayout.object.equals("szescian"))
//this.insert(load(), 6);
this.setText("load1()");
}
public static String load() {
scan = null;
try
{
scan = new Scanner(new File("res/czaszka/czaszka.txt"));
}
catch(Exception e)
{
System.out.println("File not found");
}
while(scan.hasNext())
{
line = scan.nextLine();
information += line + "\n";
}
scan.close();
return information;
}
public static String load1() {
scan = null;
try
{
scan = new Scanner(new File("res/szescian/szescian.txt"));
}
catch(Exception e)
{
System.out.println("File not found");
}
while(scan.hasNext())
{
line = scan.nextLine();
information += line + "\n";
}
scan.close();
return information;
}
}
przykładowy kod przycisku:
class czaszkaButton extends JButton implements ActionListener {
public czaszkaButton() {
super("Czaszka");
addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
MyFrame.stopOpenGL();
startOpenGL();
object = "czaszka" ;
MyFrame.cardLayout.show(MyFrame.cardPanel, "1");
}
}