Home > Back-end >  Why my program debugging show only a title bar, no any component?
Why my program debugging show only a title bar, no any component?

Time:09-21

Seems to be a problem, pack, but I don't know how to change
 import Java awt. *; 
Import the Java. The awt. Event. An ActionEvent;
Import the Java. IO. *;
import javax.swing.*;
Public class Ftest extends JFrame {
Private JScrollPane scrollPane;
Private JPanel jContentPane=null;
Private JTextArea JTextArea=null;
Private JButton openButton=null;
Private JButton closeButton=null;
Private JPanel controlPanel=null;




Private JTextArea getjTextArea () {

If (jTextArea==null) {
JTextArea=new jTextArea ();
}
Return jTextArea;
}
Private JPanel getControlPanel () {
If (controlPanel==null) {
FlowLayout FlowLayout=new FlowLayout ();
FlowLayout. SetVgap (1);
ControlPanel=new JPanel ();
ControlPanel. SetLayout (flowLayout);
ControlPanel. Add (getOpenButton (), null);
ControlPanel. Add (getCloseButton (), null);
}
Return controlPanel;
}
Private JButton getOpenButton () {
If (openButton==null) {
OpenButton=new JButton ();
OpenButton. SetText (" written to the file ");
OpenButton. AddActionListener (new Java. The awt. Event. The ActionListener () {
@ Override
Public void actionPerformed (an ActionEvent e) {
The File File=new File (" D: \ \ TPG TXT ");
Try {
FileWriter out=new FileWriter (file);
String s=jTextArea. GetText ();
Out. Write (s);
out.close();
{} the catch (IOException e1)
E1. PrintStackTrace ();
}
}
});
}
Return openButton;
}
Private JButton getCloseButton () {
If (closeButton==null) {
CloseButton=new JButton ();
CloseButton. SetText (" read the file ");
CloseButton. AddActionListener (new Java. The awt. Event. The ActionListener () {
@ Override
Public void actionPerformed (an ActionEvent e) {
The File File=new File (" D: \ \ TPG TXT ");
Try {

FileReader in=new FileReader (file);
Char byt []=new char [1024].
Int len=in. Read (byt);
JTextArea. SetText (new String (byt, 0, len));
in.close();
{} the catch (Exception e1)
E1. PrintStackTrace ();
}
}
});
}
Return the closeButton;
}

Public Ftest () {
Super ();
The initialize ();
}
Private JPanel the initialize () {
If (jContentPane==null) {
JContentPane=new JPanel ();
JContentPane. SetLayout (new BorderLayout ());
JContentPane. Add (getScrollPane (), BorderLayout. CENTER);
JContentPane. Add (getControlPanel (), BorderLayout. SOUTH);
}
Return jContentPane;
}

Public static void main (String [] args) {
Ftest thisClass=new Ftest ();
ThisClass. Pack ();
ThisClass. SetDefaultCloseOperation (JFrame. EXIT_ON_CLOSE);
ThisClass. SetVisible (true);
}
Protected the JScrollPane getScrollPane () {
If (scrollPane==null) {
ScrollPane=new JScrollPane ();
ScrollPane. SetViewportView (getjTextArea ());
}
Return the scrollPane;
}
}
  • Related