import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.Scanner;
import javax.swing.filechooser.*;
import javax.swing.ScrollPaneConstants;
public class validatiorGUI implements ActionListener
{
JFrame frame = new JFrame("C0015665");
JFileChooser chooser = new JFileChooser();
JPanel aPanel = new JPanel();
// create text area and buttons
JTextArea area = new JTextArea();
JButton openButton = new JButton("Open");
JButton saveButton = new JButton("Save");
JButton validateButton = new JButton("Validate");
Scanner input;
String a;
public void validatorGUI()
{//Default constructor
}
public void userInterface()
{
FileNameExtensionFilter filterTxt = new FileNameExtensionFilter(
"HTML files (.html)", "html");
FileNameExtensionFilter filterTxt1 = new FileNameExtensionFilter(
"XML files (.xml)", "xml");
//set up frame
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(700,700);
frame.setContentPane(aPanel);
aPanel.setLayout(null);
openButton.setBounds(5, 5, 100, 60);
aPanel.add(openButton);
saveButton.setBounds(150, 5, 100, 60);
aPanel.add(saveButton);
validateButton.setBounds(300, 5, 100, 60);
aPanel.add(validateButton);
area.setBounds(5, 100, 650, 550);
aPanel.add(area);
//add drop down choices
chooser.addChoosableFileFilter(filterTxt);
chooser.addChoosableFileFilter(filterTxt1);
//add action listener events
openButton.addActionListener(this);
validateButton.addActionListener(this);
}//end function
public void loadFile()
{
try{
int retValue = chooser.showSaveDialog(frame);
if(retValue == chooser.APPROVE_OPTION)
{
File newFile = chooser.getSelectedFile();
input = new Scanner(newFile);
while(input.hasNextLine())
{
String word = input.nextLine() + "\n";
a = a + word;
area.setText(a);
}//end while loop
}//end if
}//end try
catch(Exception e)
{
e.printStackTrace();
}//end catch
}//end function
public void findTags()
{
//function to find character and push onto stack??
}//end method
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == openButton)
{
loadFile();
}
if(e.getSource() == validateButton)
{
findTags();
}
}//end action event function
}
my problem is im taking in a file using JFileChooser - however i do not now how to search through the text area line by line to look for a character (an opening < ) which i can then push on to a stack(which ill implement later). the main is another class which calls the userInterface function.