Hallo Leute,
ich suche jetzt schon seit geraumer Zeit nach einer Lösung. Zuvor habe ich verzweifelt versucht, das Problem eigenständig zu lösen. Leider ohne Erfolg.
Ich habe mir vor einiger Zeit ein kleines Programm mit VB geschrieben, was ich jetzt in Java umsetzen möchte. Nennen wir es Neugier oder Horizonteweiterung.
Mein Problem: Ich möchte gerne einen Text in eine JTextArea schreiben. Das mit einem JButton, der eine "fremde" Klasse aufruft, die es wiederrum über eine Methode an die JTextArea weitergibt.
Hier der Code. Ich nutze NetBeans...
hier die GUI
und hier die Beispielklasse:
Was mache ich nur falsch? Es wird nichts übergeben!!!
Ciao
Timo
ich suche jetzt schon seit geraumer Zeit nach einer Lösung. Zuvor habe ich verzweifelt versucht, das Problem eigenständig zu lösen. Leider ohne Erfolg.
Ich habe mir vor einiger Zeit ein kleines Programm mit VB geschrieben, was ich jetzt in Java umsetzen möchte. Nennen wir es Neugier oder Horizonteweiterung.
Mein Problem: Ich möchte gerne einen Text in eine JTextArea schreiben. Das mit einem JButton, der eine "fremde" Klasse aufruft, die es wiederrum über eine Methode an die JTextArea weitergibt.
Hier der Code. Ich nutze NetBeans...
hier die GUI
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mytest;
/**
*
* @author Timo
*/
public class TestFrame extends javax.swing.JFrame {
/**
* Creates new form TestFrame
*/
public TestFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton1))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 159, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
TestString.TestTheString();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url]
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TestFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TestFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TestFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TestFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TestFrame().setVisible(true);
}
});
}
public void PrintMessage (String myMessage) {
jTextArea1.setText(myMessage);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}
und hier die Beispielklasse:
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mytest;
/**
*
* @author Timo
*/
public class TestString {
public static void TestTheString () {
String strString = "Dieser Text soll in die TextArea!";
TestFrame tf = new TestFrame();
tf.PrintMessage(strString);
}
}
Was mache ich nur falsch? Es wird nichts übergeben!!!
Ciao
Timo