import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.s
ID: 3538985 • Letter: I
Question
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class Exercise31_1 extends JApplet { private JTextField jtfUnicode = new JTextField(5); private JTextArea jtaUnicode = new JTextArea(); private String hexCode; private int hexNumber; public void init() { JPanel p1 = new JPanel(new BorderLayout()); p1.add(jtfUnicode, BorderLayout.CENTER); p1.setBorder(new TitledBorder("Specify Unicode")); JPanel p2 = new JPanel(new BorderLayout()); p2.add(new JScrollPane(jtaUnicode), BorderLayout.CENTER); jtaUnicode.setEditable(false); add(p1, BorderLayout.NORTH); add(p2, BorderLayout.CENTER); //jtaUnicode.append("u4F20"); jtfUnicode.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { hexCode = jtfUnicode.getText().trim(); hexNumber = HexToDecimalConversion.hexToDecimal(hexCode); for (int i = 0; i < 20; i++) { jtaUnicode.append(hexCode + " "); for (int j = 1; j < 16; j++) { hexNumber++; hexCode = Decimal2HexConversion.decimalToHex(hexNumber); jtaUnicode.append(hexCode+ ","); } jtaUnicode.append(" "); hexNumber++; hexCode = Decimal2HexConversion.decimalToHex(hexNumber); } } }); } public static void main(String[] args) { Exercise31_1 applet = new Exercise31_1(); JFrame frame = new JFrame("Unicode viewer"); frame.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); frame.setSize(500, 300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
Explanation / Answer
Given a String as input, you could use an Integer parse method to convert that to an int value which you could then increment easily and convert its new value to hex again by using another of the Integer class's methods.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.