Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please read my question if you post copy and pasted code you will get a negative

ID: 3834650 • Letter: P

Question

Please read my question if you post copy and pasted code you will get a negative review.

This needs to be done in java

In this program, you are going to read in a file, and you are going to parse it onto a stack and determine if it is syntactically correct. You will check for all open and close curly braces, open and closed parentheses, and you will check for all double quotes. You should also allow the user to choose their own file. This should be done graphically. Please use your own implementation of a stack.

Start with something like this:

public class MainFrame {

public static void main(String[] args) {

// Create an instance of the frame

JFrame myFrame = new JFrame("Basic Example");

// set the default close operation (i.e. when they click the x button) myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// add the panel to the frame myFrame.getContentPane().add(new MainPanel());

// this make sure whatever is in the panel fits in the frame myFrame.pack();

// make sure the frame is visible - it's not visible by default myFrame.setVisible(true);

}

Explanation / Answer

----------------------------------------------Solution Read File----------------------------------------------


package chegg2;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JFileChooser;
import javax.swing.JFrame;


public class MainFrame extends JFrame {

public MainFrame() {
initComponents();
}


@SuppressWarnings("unchecked")   
private void initComponents() {

fileChooser = new javax.swing.JFileChooser();
browsButton = new javax.swing.JButton();
browseTextField = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
fileTextArea = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

browsButton.setText("Browse");
browsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
browsButtonActionPerformed(evt);
}
});

browseTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
browseTextFieldActionPerformed(evt);
}
});

fileTextArea.setColumns(20);
fileTextArea.setRows(5);
jScrollPane1.setViewportView(fileTextArea);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(browseTextField)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(browsButton))
.addGroup(layout.createSequentialGroup()
.addGap(4, 4, 4)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)))
.addGap(26, 26, 26))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(browsButton)
.addComponent(browseTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
.addContainerGap())
);

pack();
}   

private void browseTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}   

private void setFile(File file){
  
browseTextField.setText(file.getPath());
}
  
private void putIntoStack(File file){
  
String string = "";
ArrayList<String> fileList = new ArrayList<String>();
try{
Scanner scanner = new Scanner(file).useDelimiter(",\s*");
  
while(scanner.hasNext()){
string = scanner.next();
fileList.add(string);
  
}
scanner.close();
fileTextArea.setText(fileList.toString());
  
String strArrString[] = fileList.toArray(new String[0]);
for(String str : strArrString){


System.out.println(str);
  
}

}catch(FileNotFoundException e){
  

}catch(NullPointerException e){
  
  
}
  
  
}
private void browsButtonActionPerformed(java.awt.event.ActionEvent evt) {
fileChooser = new JFileChooser();
  
if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
  
  
File file = fileChooser.getSelectedFile();
if (file != null) {
setFile(file);
}
putIntoStack(file);   
}
}   

/**
* @param args the command line arguments
*/
public static void main(String args[]) {

try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
MainFrame mainFrame = new MainFrame();
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
});
}

// Variables declaration - do not modify   
private javax.swing.JButton browsButton;
private static javax.swing.JTextField browseTextField;
private javax.swing.JFileChooser fileChooser;
private javax.swing.JTextArea fileTextArea;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration   
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote