I'm new to Java and have an issue I'm stuck with. I have created a class with a Swing UI in it which contains a jTextArea called 'jTextAreaConsole'.:
public class converterUI extends javax.swing.JFrame {
This class imports another class called 'dbConverter':
package my.converterui;
import dbToExcel.dbConverter;
dbConverter is a simple class with one method:
public class dbConverter extends common{
public static void convert(String sourceDB, String sourceQry, String destination, String objectName){
dbConverter converter = new dbConverter();
Connection con = converter.getConnection(sourceDB);
String sql = sourceQry;
ResultSet result = converter.runQuery1(con,sql);
converter.writeOut(result, objectName, destination);
closeConnection(con);
}
public static void main(String[] args) {
}
}
the runQuery and writeOut methods are detailed in the 'common' class extended by this class. What I want to do is in the common class reference the jTextAreaConsole object to append text to it. I've already tried using super.jTextAreaConsole.append(str) and this runs but doesn't do anything.
Edit: Basic example here:
package myproject;
public class MyProject extends mainForm{
public static void main(String[] args) {
mainForm.main(null);
}
public void clickAction(){
passText();
}
}
package myproject;
class mainForm extends javax.swing.JFrame {
public void passText(){
jTextArea1.append("This is a test");
}
public mainForm() {
initComponents();
}
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton1.setText("Click me");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(42, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(162, 162, 162))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(46, 46, 46)
.addComponent(jButton1)
.addGap(27, 27, 27)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(25, Short.MAX_VALUE))
);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new mainForm().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
}
Thanks,