Java language
(a) Create a class HexEditor with a constructor which creates a 5x10 text area in a Frame. Also add a pull-down menu with a menu item "Load". Copy the class as the answer to this part.

(b) Create another class TestHexEditor with a main() method which creates an object anEditor of the class HexEditor and displays the frame in part (a) using setVisible(true). Copy the class as the answer to this part.
(c) Make changes to the class HexEditor so that it implements ActionListener. In the constructor of the class HexEditor, add the current object as the action listener of the "Load" menu item. Write the corresponding method actionPerformed() which displays a dialog box asking for a file name and load content of the file to the text area using FileInputStream. You can assume the file is a byte file and it exists. Copy the changed/added lines and the new method as the answers to this part.
(d) We will use the BorderLayout manager. Modify the constructor to put the text area on the left, add a label containing a space in the middle, add a new text area (with width 20) on the right, and a button at the bottom. The resulting window is showed below (after a file is loaded). Copy the changed/added lines as the answers to this part.

(e) Modify the method actionPerformed() so that when the update button is pressed, a hexidecimal version of the file is displayed on the right, in which each byte is represented by two hexidecimal digits and followed by a space. You can use Integer.toHexString('B') to convert a byte 'B' to a hexidecimal string. A sample window is shown below (where '0A' on the hex window corresponds to a newline character). Copy the changed/added lines as the answers to this part.

(f) In the pull-down menu, add a "Save" menu item so that the original file can be replaced by the content of the text area on the left. You need to modify the method actionPerformed() to achieve this. If no file was loaded but the user directly type something on the left text area, ask for the file name using a dialog box and replace any existing file. Copy the changed/added lines as the answers to this part.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class HexEditor extends javax.swing.JFrame implements ActionListener{
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jmItemLoad;
private javax.swing.JTextArea txtPlainTextData;
private javax.swing.JTextArea txtHexData;
private javax.swing.JLabel lblSeparator;
private javax.swing.JButton btnUpdateHex;
public HexEditor() {
initComponents();
jmItemLoad.addActionListener(this);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
this.setSize(450,300);
txtPlainTextData = new javax.swing.JTextArea();
txtHexData = new javax.swing.JTextArea();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jmItemLoad = new javax.swing.JMenuItem();
lblSeparator = new javax.swing.JLabel();
btnUpdateHex = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(true);
txtPlainTextData.setColumns(10);
txtPlainTextData.setRows(5);
txtHexData.setColumns(20);
txtHexData.setRows(5);
lblSeparator.setText(" ");
jMenu1.setText("File");
jMenu1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
jMenu1.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
jmItemLoad.setText("Load");
jMenu1.add(jmItemLoad);
btnUpdateHex.setText("Update hex");
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
this.add(txtPlainTextData, BorderLayout.LINE_START);
this.add(lblSeparator, BorderLayout.CENTER);
this.add(txtHexData,BorderLayout.LINE_END);
this.add(btnUpdateHex,BorderLayout.PAGE_END);
pack();
}
@Override
public void actionPerformed(ActionEvent e) {
NewJDialog getFileDialog = new NewJDialog(this, true);
fileName = getFileDialog.showDialog();
// File reading
File file = new File(fileName);
FileInputStream fStream = null;
StringBuffer fileData = new StringBuffer("");
StringBuffer hexData = new StringBuffer("");
int ch;
try
{
fStream = new FileInputStream(file);
while((ch=fStream.read()) != -1)
{
fileData.append((char)ch);
hexData.append(String.format("%02X",ch)+" ");
}
fStream.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
// Load data to text area
this.txtPlainTextData.setText(fileData.toString());
this.txtHexData.setText(hexData.toString());
}
private String fileName;
}
public class TestHexEditor {
public static void main(String[] args) {
HexEditor hexEditor = new HexEditor();
hexEditor.setVisible(true);
}
}
import javax.swing.border.Border;
import java.awt.*;
public class NewJDialog extends javax.swing.JDialog {
public NewJDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
this.setSize(300,200);
this.setTitle("Load File");
jLabel1 = new javax.swing.JLabel();
jtxtFile = new javax.swing.JTextField();
jbtnLoadFile = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
jtxtFile.setColumns(30);
jtxtFile.setText("Byte File Path");
jLabel1.setText("Enter a file to load");
jbtnLoadFile.setText("Load");
jbtnLoadFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fileName = jtxtFile.getText();
dispose();
}
});
this.add(jLabel1, BorderLayout.PAGE_START);
this.add(jtxtFile,BorderLayout.CENTER);
this.add(jbtnLoadFile,BorderLayout.LINE_END);
pack();
}
String showDialog()
{
setVisible(true);
return fileName;
}
private javax.swing.JButton jbtnLoadFile;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField jtxtFile;
private String fileName;
}
Note: I haven't added update logic in this. You will have to do that your own. Let me know if you face any issues with above class.
when you provide file name, provide fully qualified path
Screen shots



Java language (a) Create a class HexEditor with a constructor which creates a 5x10 text area...
(b) Write a class Conversion containing the following methods: (i) constructor: which builds the frame shown on the right side. The frame consists of a text field for inputting a NZD amount, a label with 10 spaces for an equivalent HKD amount, and a button to start the calculation. Declare any necessary attributes in the class and add appropriate action listeners for future use. Copy the class, including import statement(s), as the answers to this part Calculate (ii) actionPerformed :...
JAVA The following is about creating a class Ruler and testing it. (i) Create a class Ruler with the attributes brand (which is a string) and length (an integer) which are used to store the brand and length of the ruler respectively. Write a constructor Ruler(String brand, int length) which assigns the brand and length appropriately. Write also the getter/setter methods of the two attributes. Save the content under an appropriate file name. Copy the content of the file as...
MyMenuFrame.java, MyMenuFrameTest.java, a. The title of the frame is “MyNotepad”. b. Create and add border layout. c. Create a text area to display contents. Add the text area to the center of the border layout. d. Create a menu bar. e. Create a file menu. Set mnemonic for file menu. It is “F”. File menu includes three menu items. f. Add a separator between each menu item in the file menu. i. Open 1. Add a short cut for...
Language : JAVA Part A Create a class CompanyDoc, representing an official document used by a company. Give it a String title and an int length. Throughout the class, use the this. notation rather than bare instance variables and method calls. Add a default constructor. Add a parameterized constructor that takes a value for title. Use this( appropriately to call one constructor from another. Add a toString(), which returns a string with the title, and the length in parentheses. So...
Create a LIFO class with following methods in java - public LifoList() The default constructor for LifoList class which will initialize your class variables maxSize to 0 and the int array to null. public LifoList(int maxSize) The constructor for LifoList class which takes the int input maxSize to initialize the size of the array. You should NOT reinitialize the array elsewhere. For example, creating an object as new LifoList(5) should create a LifoList whose maximum size is 5. If the...
*Java* Given the attached Question class and quiz text, write a driver program to input the questions from the text file, print each quiz question, input the character for the answer, and, after all questions, report the results. Write a Quiz class for the driver, with a main method. There should be a Scanner field for the input file, a field for the array of Questions (initialized to 100 possible questions), and an int field for the actual number of...
Java Programming The following is about creating a class Fish and testing it. In every part, correct any syntax errors indicated by NetBeans until no such error messages. (i) Create a class Fish with the attributes name and price. The attributes are used to store the name and the price of the fish respectively. Choose suitable types for them. You can copy the class Counter on p.17 of the unit and modify the content. Copy the content of the file...
Java Please - Design and implement a class Triangle. A constructor should accept the lengths of a triangle’s 3 sides (as integers) and verify that the sum of any 2 sides is greater than the 3rd(i.e., that the 3 sides satisfy the triangle inequality). The constructor should mark the triangle as valid or invalid; do not throw an exception. Provide get and set methods for the 3 sides, and recheck for validity in the set methods. Provide a toString method...
I need code in java
The Student class:
CODE IN JAVA:
Student.java file:
public class Student {
private String name;
private double gpa;
private int idNumber;
public Student() {
this.name = "";
this.gpa = 0;
this.idNumber = 0;
}
public Student(String name, double gpa, int
idNumber) {
this.name = name;
this.gpa = gpa;
this.idNumber = idNumber;
}
public Student(Student s)...
java language
Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...