Hi!, I have created a user inteface named "helpGUI". This user interface contains a JTextArea.
I also have created a text file named "help.txt".
I need to show the "help.txt" file in the JTextArea.
As I'm new to JAVA I have no idea how to do this. Given below is the code that i have done upto now.
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.border.*;
class helpGUI
{
JFrame frame;
JPanel panel1, panel2, panel3;
JTextArea txtHelp;
JScrollPane scrollHelp;
JLabel lblImg;
JButton btnOk;
public helpGUI()
{
java.io.BufferedReader reader = new java.io.BufferedReader(new FileReader("help.txt"));
String temp = null;
StringBuffer message = new StringBuffer();
String newLine = System.getProperty("line.separator");
//Scroll Panel
panel1 = new JPanel();
panel1.setLayout(new GridBagLayout());
//Options Panel
panel2 = new JPanel();
panel2.setLayout(new FlowLayout(FlowLayout.RIGHT));
//Image Panel
panel3 = new JPanel();
panel3.setLayout(new GridBagLayout());
lblImg = new JLabel(new ImageIcon("helpIMAGE.jpg"));
lblImg.setHorizontalAlignment(JLabel.CENTER);
panel3.add(lblImg);
//Help ScrollPane
txtHelp = new JTextArea(30, 50);
txtHelp.setLineWrap(true);
txtHelp.setText("QuickData Management System");
txtHelp.setEditable(false);
scrollHelp = new JScrollPane(txtHelp);
scrollHelp.setEnabled(false);
panel1.add(scrollHelp, getConstraints(0, 4, 2, 1, GridBagConstraints.EAST));
//Button - Ok
btnOk = new JButton("Ok");
panel1.add(btnOk, getConstraints(0, 5, 2, 1, GridBagConstraints.EAST));
btnOk.addActionListener(new okListener());
frame.getContentPane().add(panel1);
frame.getContentPane().add(panel2);
frame.getContentPane().add(panel3);
frame.getContentPane().add(BorderLayout.CENTER, panel1);
frame.getContentPane().add(BorderLayout.SOUTH, panel2);
frame.getContentPane().add(BorderLayout.NORTH, panel3);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
}
private GridBagConstraints getConstraints(int gridx,int gridy, int gridwidth,int gridheight,int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5,5,5,5);
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = GridBagConstraints.WEST;
return c;
}
class okListener implements ActionListener
{
public void actionPerformed(ActionEvent ev)
{
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(false);
}
}
public static void main(String args[])
{
helpGUI st = new helpGUI();
}
}
Please help me with this problem.