Witam
Na początku mówię, że jestem początkujący i dopiero uczę się Javy.
Piszę program do konwertowania jednostek (np. tony --->gramy, decymetry--->milimetry itp.). Chciałem zrobić opcję konwertowania liczb w systemie dziesiętnym na inne systemy liczbowe. Napisałem kod, ale coś nie tryka. W oknie, gdzie powinna pokazać się liczba w innym systemie nic się nie pokazuje.
Jest to wycięta część kodu z programu
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.plaf.SeparatorUI;
public class Swing extends JFrame implements ActionListener
{
int system1, system2;
JButton bKonwertujS;
JLabel lSystemy, lRSystemy;
JComboBox cbSystemyIn, cbSystemyOut;
JTextField tfSystemyIn, tfSystemyOut;
public Swing()
{
setSize(500, 500);
setLocation(50, 20);
setLayout(null);
lSystemy = new JLabel("SYSTEMY LICZBOWE");
lSystemy.setFont(new Font("SansSerif", Font.BOLD, 18));
lSystemy.setBounds(250, 10, 200, 20);
add(lSystemy);
lRSystemy = new JLabel("=");
lRSystemy.setBounds(350, 60, 20, 20);
add(lRSystemy);
tfSystemyIn = new JTextField();
tfSystemyIn.setBounds(275, 60, 70, 20);
add(tfSystemyIn);
tfSystemyIn.addActionListener(this);
tfSystemyOut = new JTextField();
tfSystemyOut.setBounds(365, 60, 70, 20);
add(tfSystemyOut);
tfSystemyOut.addActionListener(this);
cbSystemyIn = new JComboBox();
cbSystemyIn.setBounds(275, 40, 70, 20);
cbSystemyIn.addItem("dziesiętny");
add(cbSystemyIn);
cbSystemyIn.addActionListener(this);
cbSystemyOut = new JComboBox();
cbSystemyOut.setBounds(365, 40, 70, 20);
cbSystemyOut.addItem("binarny");
cbSystemyOut.addItem("ósemkowy");
cbSystemyOut.addItem("dziesiętny");
cbSystemyOut.addItem("szesnastkowy");
add(cbSystemyOut);
cbSystemyOut.addActionListener(this);
bKonwertujS = new JButton("Konwertuj");
bKonwertujS.setBounds(280, 80, 150, 20);
add(bKonwertujS);
bKonwertujS.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object z = e.getSource();
if(z == miZamknij)
{
int odp = JOptionPane.showConfirmDialog(this, "Czy na pewno chcesz wyjść?", "Wyjście", JOptionPane.YES_NO_OPTION);
if(odp == JOptionPane.YES_OPTION)
dispose();
}
else if(z == bKonwertujS)
{
ObliczanieLiczb();
}
}
void ObliczanieLiczb()
{
int lD1;
String lD2 = null;
String jS2 = cbSystemyIn.getSelectedItem().toString();
lD1 = Integer.parseInt(tfSystemyIn.getText());
if(jS2 == "binarny")
lD2 = Integer.toBinaryString(lD1);
else if(jS2 == "ósemkowy")
lD2 = Integer.toOctalString(lD1);
else if(jS2 == "szesnastkowy")
lD2 = Integer.toHexString(lD1);
tfSystemyOut.setText(lD2);
}
public static void main(String[] args)
{
Swing okno = new Swing();
okno.setDefaultCloseOperation(EXIT_ON_CLOSE);
okno.setVisible(true);
}
}