Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Java program title: Enter decimal integer, output integer in binary, octal and hexadecimal form respectively, and the text boxes in the graphical interface are arranged vertically for solution.
Java program title: Enter decimal integer, output integer in binary, octal and hexadecimal form respectively, and the text boxes in the graphical interface are arranged vertically for solution.
import Java . awt . gridlayout;

import javax . swing . jframe;

import javax . swing . jlabel;

import javax . swing . jpanel;

import javax . swing . jtextfield;

import javax . swing . event . document event;

import javax . swing . event . document listener;

publicclassTest{

publicstaticvoidmain(String[]args){

JPaneltp = newJPanel(newGridLayout(0,2));

Tp.add(newJLabel ("Enter 10 decimal number");

finaljtextfieldtf 10 = newJTextField();

TP . add(TF 10);

TP . add(new jlabel(" binary "));

finaljtextfieldtf 2 = newJTextField();

TP . add(tf2);

TP . add(new jlabel(" octal "));

finaljtextfieldtf 8 = newJTextField();

TP . add(tf8);

Tp.add(newJLabel(" 16 hexadecimal "));

finaljtextfieldtf 16 = newJTextField();

TP . add(TF 16);

tf 10.getDocument()。 addDocumentListener(newDocumentListener(){

privatevoidcheck(){

Try {

longn = long . parse long(TF 10 . gettext());

tf2.setText(Long.toString(n,2));

tf8.setText(Long.toString(n,8));

TF 16 . settext(long . tostring(n, 16));

}catch(Exceptionex){

tf2.setText("ERR。" );

tf8.setText("ERR。" );

tf 16.setText("ERR。 );

}

}

@ Overlay

publicfoidinsertupdate(DocumentEvente){

check();

}

@ Overlay

publicvidremoveupdate(documente){

check();

}

@ Overlay

publicvidchangedupdate(documente){