Okay, so I'm trying to make a hex editor, and I'm trying to make a load JMenuItem, but it's not working. The JFileChooser OpenDialog just doesn't show up, and no errors are being shown.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Vector;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
public class HexEditor extends JFrame{
JTextArea textArea;
JFileChooser chooser;// = new JFileChooser();
FileInputStream fin;
JMenuBar menuBar;
JMenu file;
JMenuItem load;
public HexEditor(){
super("Cypri's java hex editor");
chooser = new JFileChooser();
load = new JMenuItem("Load");
load.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {
try{
openFile();
fin = new FileInputStream(chooser.getSelectedFile());
int ch;
StringBuffer strContent = new StringBuffer("");
for(int i = 0; (ch = fin.read()) != -1; i++){
String s = Integer.toHexString(ch);
if(s.length() < 2)
s = "0" + Integer.toHexString(ch);
if(i < 10)
strContent.append(" " + s.toUpperCase());
else{
strContent.append(" " + s.toUpperCase() + "\n");
i = 0;
}
}
textArea.setText(strContent.toString());
//textArea.setWrapStyleWord(true);
//textArea.setColumns(50);
//textArea.setRows(50);
}
catch(Exception e){
e.printStackTrace();
}
}
});
file = new JMenu("File");
file.add(new JMenuItem("Load"));
menuBar = new JMenuBar();
menuBar.add(file);
textArea = new JTextArea();
textArea.setSize(300,300);
textArea.setText("Hello\n");
textArea.append(" world!");
setSize(640, 480);
//getContentPane().setBackground(Color.);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(BorderLayout.NORTH, menuBar);
getContentPane().add(BorderLayout.WEST, textArea);
pack();
setVisible(true);
}
public void openFile(){
chooser.showOpenDialog(this);
}
public static void main(String[] args){
HexEditor app = new HexEditor();
}
}