Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How to make the program look like this? ( a ) ( b ) here is my code import javax.swing. * ; import java.awt. *
How to make the program look like this? a b here is my code import javax.swing.; import java.awt.; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.ioIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main extends JFrame private JTextField fileNameField; private JTextArea binaryTextArea; public Main setTitleBinary Editor"; setSize; setDefaultCloseOperationJFrameEXITONCLOSE; setLayoutnew BorderLayout; fileNameField new JTextField; binaryTextArea new JTextArea; binaryTextArea.setEditabletrue; JButton loadButton new JButtonLoad; JButton saveButton new JButtonSave; loadButton.addActionListenernew ActionListener @Override public void actionPerformedActionEvent e loadFile; ; saveButton.addActionListenernew ActionListener @Override public void actionPerformedActionEvent e saveFile; ; JPanel topPanel new JPanelnew FlowLayout; topPanel.addnew JLabelFile Name:"; topPanel.addfileNameField; topPanel.addloadButton; topPanel.addsaveButton; addtopPanel BorderLayout.NORTH; addnew JScrollPanebinaryTextArea BorderLayout.CENTER; private void loadFile String fileName fileNameField.getText; try Path filePath Paths.getfileName; byte fileBytes Files.readAllBytesfilePath; String binaryRepresentation bytesToBinaryfileBytes; binaryTextArea.setTextbinaryRepresentation; catch IOException ex JOptionPane.showMessageDialogthis "Error loading file: exgetMessage "Error", JOptionPane.ERRORMESSAGE; private void saveFile String fileName fileNameField.getText; String binaryCode binaryTextArea.getText; try byte modifiedBytes binaryToBytesbinaryCode; Path filePath Paths.getfileName; Files.writefilePath modifiedBytes; JOptionPane.showMessageDialogthis "File saved successfully!", "Success", JOptionPane.INFORMATIONMESSAGE; catch IOException ex JOptionPane.showMessageDialogthis "Error saving file: exgetMessage "Error", JOptionPane.ERRORMESSAGE; private String bytesToBinarybyte bytes StringBuilder binaryStringBuilder new StringBuilder; for byte b : bytes binaryStringBuilder.appendStringformats Integer.toBinaryStringb & xFFreplace; return binaryStringBuilder.toString; private byte binaryToBytesString binary int length binary.length; byte result new bytelength ; for int i ; i length; i String byteStr binary.substringi i ; resulti byte Integer.parseIntbyteStr; return result; public static void mainString args SwingUtilities.invokeLaternew Runnable @Override public void run new MainsetVisibletrue; ;
How to make the program look like this? a
b here is my code import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.ioIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main extends JFrame
private JTextField fileNameField;
private JTextArea binaryTextArea;
public Main
setTitleBinary Editor";
setSize;
setDefaultCloseOperationJFrameEXITONCLOSE;
setLayoutnew BorderLayout;
fileNameField new JTextField;
binaryTextArea new JTextArea;
binaryTextArea.setEditabletrue;
JButton loadButton new JButtonLoad;
JButton saveButton new JButtonSave;
loadButton.addActionListenernew ActionListener
@Override
public void actionPerformedActionEvent e
loadFile;
;
saveButton.addActionListenernew ActionListener
@Override
public void actionPerformedActionEvent e
saveFile;
;
JPanel topPanel new JPanelnew FlowLayout;
topPanel.addnew JLabelFile Name:";
topPanel.addfileNameField;
topPanel.addloadButton;
topPanel.addsaveButton;
addtopPanel BorderLayout.NORTH;
addnew JScrollPanebinaryTextArea BorderLayout.CENTER;
private void loadFile
String fileName fileNameField.getText;
try
Path filePath Paths.getfileName;
byte fileBytes Files.readAllBytesfilePath;
String binaryRepresentation bytesToBinaryfileBytes;
binaryTextArea.setTextbinaryRepresentation;
catch IOException ex
JOptionPane.showMessageDialogthis "Error loading file: exgetMessage "Error", JOptionPane.ERRORMESSAGE;
private void saveFile
String fileName fileNameField.getText;
String binaryCode binaryTextArea.getText;
try
byte modifiedBytes binaryToBytesbinaryCode;
Path filePath Paths.getfileName;
Files.writefilePath modifiedBytes;
JOptionPane.showMessageDialogthis "File saved successfully!", "Success", JOptionPane.INFORMATIONMESSAGE;
catch IOException ex
JOptionPane.showMessageDialogthis "Error saving file: exgetMessage "Error", JOptionPane.ERRORMESSAGE;
private String bytesToBinarybyte bytes
StringBuilder binaryStringBuilder new StringBuilder;
for byte b : bytes
binaryStringBuilder.appendStringformats Integer.toBinaryStringb & xFFreplace;
return binaryStringBuilder.toString;
private byte binaryToBytesString binary
int length binary.length;
byte result new bytelength ;
for int i ; i length; i
String byteStr binary.substringi i ;
resulti byte Integer.parseIntbyteStr;
return result;
public static void mainString args
SwingUtilities.invokeLaternew Runnable
@Override
public void run
new MainsetVisibletrue;
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started