So, my data are stored in a file, called log.txt, and I want to view the content of it, in GUI. So i've got these two classes which i'm using, one is Engine, where I read the log.txt file, and the other one is GUI, where is used to apply the methods used in Engine.
So, in my engine, I've got these codes:
public void loadLog()
{
try
{
java.io.File cpFile = new java.io.File( "log.txt" );
if ( cpFile.exists() == true )
{
File file = cpFile;
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
String strLine="";
String logPrint="";
fis = new FileInputStream ( file );
// Here is BufferedInputStream added for fast reading
bis = new BufferedInputStream ( fis );
dis = new DataInputStream ( bis );
// New Buffer Reader
BufferedReader br = new BufferedReader( new InputStreamReader( fis ) );
while ( ( strLine = br.readLine() ) != null )
{
StringTokenizer st = new StringTokenizer ( strLine, ";" );
while ( st.hasMoreTokens() )
{
logPrint = st.nextToken();
System.out.println(logPrint);
}
log = new Log();
//regis.addLog( log );
}
}
}
catch ( Exception e ){
}
}
and then, in my GUI, I'd try to apply the codes used in my engine:
// create exit menu
Logout = new JMenu("Exit");
// create JMenuItem for about menu
reportItem = new JMenuItem ( "Report" );
// add about menu to menuBar
menuBar.add ( Logout );
menuBar.setBorder ( new BevelBorder(BevelBorder.RAISED) );
Logout.add ( reportItem );
/* --------------------------------- ACTION LISTENER FOR ABOUT MENU ------------------------------------------ */
reportItem.addActionListener ( new ActionListener()
{
public void actionPerformed ( ActionEvent e )
{
engine.loadLog();
mainPanel.setVisible (false);
mainPanel = home();
toolBar.setVisible(false);
vasToolBar.setVisible(false);
cpToolBar.setVisible(false);
add ( mainPanel, BorderLayout.CENTER );
add ( toolBar, BorderLayout.NORTH );
toolBar.setVisible(false);
mainPanel.setVisible ( true );
pack();
setSize(500, 500);
}
});
NOW,
my question is, how can I print out whatever is read in my Engine's method, inside the GUI part? I want them to be either inside a JLabel or JTextArea. How am I supposed to do that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…