EasyJFrame : Reusable JFrame class

Here, i am going to describe a reusable jFrame class, which can be used as substitute of standard console output.

Resuable JFrame CODE:

package EasyGUI;
import javax.swing.JFrame;
public class EasyJFrame extends JFrame {
static JTextArea jta;
public
EasyJFrame() {
   showGUI();
}
private void showGUI() {
   jta = new JTextArea();
   JScrollPane scrollBar = new JScrollPane(jta,
               JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
               JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
   add(scrollBar);
   setSize(400,550);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   setVisible(true);
}
public void out(String str) {
   jta.append(str);
}
public void outln(String str) {
   jta.append("\n" + str);
}
}

Testing ....
public class TestApplication extends EasyJFrame{
public TestApplication(){
   // instead of doing this 
   System.out.println("output");
   //just do
   out("output"); // shows output in GUI... 
}

public static void main(String[] args) {
    new TestApplication();
}
}

No comments :

Post a Comment

Your Comment and Question will help to make this blog better...