I have a project that I'm a bit stuck on. I have a JFrame
with a JTextArea
and a button when the button is clicked it is to open the test class in the text area of the frame. So my question is, how do I get the test class to open in the text area of the frame?
I have tried getText(test())
but it say that can not find symbol method test.
This is my JFrame
code:
package sunday;
/**
*
* @author warwick
*/
public class sunday1 extends javax.swing.JFrame {
/**
* Creates new form sunday1
*/
public sunday1() {
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() {
jScrollPane1 = new javax.swing.JScrollPane();
TxtField = new javax.swing.JTextArea();
btnOpen = new javax.swing.JToggleButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
TxtField.setColumns(20);
TxtField.setRows(5);
jScrollPane1.setViewportView(TxtField);
btnOpen.setText("Open");
btnOpen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOpenActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnOpen)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(57, 57, 57))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(101, 101, 101)
.addComponent(btnOpen)))
.addContainerGap(36, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnOpenActionPerformed(java.awt.event.ActionEvent evt) {
TxtField.setText(test());
}
This is my class code that has to display in the text area of the frame.
public class sundaytest {
private void test() {
System.out.println("Hello World");
}
}