Text are not visible in GUI
My text area in this program I'm working on is not visible, only the buttons are....any help appreciated.
Code:
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MyText extends JFrame {
private Toolkit toolkit;
public static int LineCount = 0; //Counts the lines.
public static String[] content;
public static void ReadFile() throws Exception {
BufferedReader TextFileReader = new BufferedReader(new FileReader("./info.txt"));
String c;
String t;
t = "Blank";
while((c = TextFileReader.readLine()) != null) {
LineCount++;
t += ","+ c;
}
t = t.replaceAll("Blank,","");
content = new String[LineCount];
content = t.split(",");
TextFileReader.close();
for(int i = 0; i < 7; i++) //Keep printing as long as i is smaller than 7, which is what I need for my text file.
System.out.println(content[i]); //prints the first part of my list of names.
}
public MyText() {
setTitle("Name and Address");
setSize(300, 400);
toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
setLocation((size.width - getWidth())/2, (size.height - getHeight())/2);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel panel = new JPanel();
getContentPane().add(panel);
panel.setLayout(null);
JButton beep = new JButton("Next");
beep.setBounds(150, 60, 80, 30);
beep.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
toolkit.beep();
for(int i = 0; i > 0; i++)
System.out.println(content[i]);
}
});
JButton close = new JButton("Back");
close.setBounds(50, 60, 80, 30);
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
toolkit.beep();
for(int i = 0; i > 0; i--)
System.out.println(content[i]);
}
});
panel.add(beep);
panel.add(close);
}
public static void main(String[] args) {
MyText buttons = new MyText();
buttons.setVisible(true);
}
}