Bunty Ranu
April 1st, 2010, 03:16 PM
Hey everybody, I'm having a bit of a challenge here with making a program. I have to create a Java Swing GUI program that opens a file as a binary stream and displays the values of each byte in Hex and as readable text. When I click the new button in my GUI it should allow me to browse for a text file, read in the characters, the display the characters alongside their Hex conversion in the text field. The format should be 16 Byte values displayed as 2 digit hex values separated by 2 spaces, then a separator | and then the text representation of these same characters. For the text representation, I need a period or dot for non-printing characters (like a carriage return) and just display the printable ones. An example of how it should be is:
AD EF 00 10 46 56 23 50 AD EF 00 10 46 56 23 50 |..aBntefg.?>..
This is my code so far:
package BinaryFileViewer;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.*;
import javax.swing.*;
/**
*
* @author Bunty
*/
public class BinaryFileViewer extends JPanel implements ActionListener
{
private JTextArea field = new JTextArea(10, 30);
private JScrollPane scrollPane = new JScrollPane(field);
private JButton newButton = new JButton("New");
private JButton quitButton = new JButton("Quit");
public BinaryFileViewer()
{
JPanel buttonPanel = new JPanel();
buttonPanel.add(newButton);
buttonPanel.add(quitButton);
this.setLayout(new BorderLayout());
this.add(buttonPanel, BorderLayout.NORTH);
this.add(scrollPane, BorderLayout.CENTER);
newButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
}
});
quitButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
System.exit(0); // exit the application
}
});
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == newButton)
{
}
else if (e.getSource() == quitButton)
System.exit(0);
}
public static void main(String[] argv)
{
JFrame frame = new JFrame("Bunty's Binary File Viewer!");
frame.getContentPane().add(new BinaryFileViewer());
frame.pack();
frame.setSize(550, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Thanks in advance for any help guys.
AD EF 00 10 46 56 23 50 AD EF 00 10 46 56 23 50 |..aBntefg.?>..
This is my code so far:
package BinaryFileViewer;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.*;
import javax.swing.*;
/**
*
* @author Bunty
*/
public class BinaryFileViewer extends JPanel implements ActionListener
{
private JTextArea field = new JTextArea(10, 30);
private JScrollPane scrollPane = new JScrollPane(field);
private JButton newButton = new JButton("New");
private JButton quitButton = new JButton("Quit");
public BinaryFileViewer()
{
JPanel buttonPanel = new JPanel();
buttonPanel.add(newButton);
buttonPanel.add(quitButton);
this.setLayout(new BorderLayout());
this.add(buttonPanel, BorderLayout.NORTH);
this.add(scrollPane, BorderLayout.CENTER);
newButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
}
});
quitButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
System.exit(0); // exit the application
}
});
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == newButton)
{
}
else if (e.getSource() == quitButton)
System.exit(0);
}
public static void main(String[] argv)
{
JFrame frame = new JFrame("Bunty's Binary File Viewer!");
frame.getContentPane().add(new BinaryFileViewer());
frame.pack();
frame.setSize(550, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Thanks in advance for any help guys.