Jeszcze mam 2 problemy
1 Chce zrobić 2 radiobuttony 1 do zmiany rozmiaru textu a 2 do przeliczania z Fah na Cel i na odwrót
2 Jak włączyć ponumerowanie linijek w tym programie co polecacie
A tu kod
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Test2 extends JFrame implements ActionListener
{
private JTextField tCal, tFan;
private JLabel lCal, lFan;
private JButton bKon;
private double tempCal, tempFan;
private ButtonGroup bgRozmiar, bgCF;
private JRadioButton rbMały, rbŚredni, rbDuży, rbCdoF, rbFdoC;
public Test2()
{
setSize(400,300);
setLayout(null);
setTitle("Przeliczanie stopni");
lCal = new JLabel("Stopnie Celsiusza");
lCal.setBounds(20,20,150,20);
add(lCal);
lFan = new JLabel("Stopnie Fahrenheita");
lFan.setBounds(20,80,150,20);
add(lFan);
tCal = new JTextField("");
tCal.setBounds(170,20,150,20);
add(tCal);
tCal.addActionListener(this);
tFan = new JTextField("");
tFan.setBounds(170,80,150,20);
add(tFan);
bKon = new JButton("Konwertuj");
bKon.setBounds(100,120,150,20);
add(bKon);
bKon.addActionListener(this);
bgRozmiar = new ButtonGroup();
rbMały = new JRadioButton("Mały", false);
rbMały.setBounds(50,150,100,20);
bgRozmiar.add(rbMały);
add(rbMały);
rbMały.addActionListener(this);
rbŚredni = new JRadioButton("Średni", true);
rbŚredni.setBounds(150,150,100,20);
bgRozmiar.add(rbŚredni);
add(rbŚredni);
rbŚredni.addActionListener(this);
rbDuży = new JRadioButton("Duży", false);
rbDuży.setBounds(250,150,100,20);
bgRozmiar.add(rbDuży);
add(rbDuży);
rbDuży.addActionListener(this);
bgCF = new ButtonGroup();
rbCdoF = new JRadioButton("Cel do Fah");
rbCdoF.setBounds(250,180,150,20);
rbCdoF.setSelected(true);
rbFdoC = new JRadioButton("Fah do Cel");
rbFdoC.setBounds(50,180,150,20);
bgCF.add(rbCdoF);
bgCF.add(rbFdoC);
add(rbCdoF);
add(rbFdoC);
}
public void actionPerformed(ActionEvent e)
{
Object zrodlo = e.getSource();
if (zrodlo==bKon );
{
if (rbCdoF.isSelected()) ;
{
tempCal = Double.parseDouble(tCal.getText());
tempFan = 32.0 + (9.0 / 5.0) * tempCal;
tFan.setText(String.valueOf(tempFan));
}
else if (rbFdoC.isSelected()) ;
{
tempFan = Double.parseDouble(tFan.getText());
tempCal = (tempFan - 32.0) * (9.0 / 5.0);
tCal.setText(String.valueOf(tempCal));
}
}
else if (zrodlo==rbMały)
{
tFan.setFont(new Font("SandSerif", Font.PLAIN, 10));
}
else if (zrodlo==rbŚredni)
{
tFan.setFont(new Font("SandSerif", Font.PLAIN, 14));
}
else if (zrodlo==rbDuży)
{
tFan.setFont(new Font("SandSerif", Font.PLAIN, 18));
}
}
public static void main(String[] args)
{
Test2 apka = new Test2();
apka.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
apka.setVisible(true);
}
}