12 Aralık 2011

12 Aralık 2011 - Lab

package lab11;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Main extends JFrame{

    private JTextField jt1,jt2;

    public Main(){
        super("Donusturucu");

        JPanel kok = new JPanel();
        this.setContentPane(kok);
        kok.setLayout(new BoxLayout(kok, BoxLayout.X_AXIS));

        // sol sutun
        JPanel sol = new JPanel();
        sol.setLayout(new BoxLayout(sol, BoxLayout.Y_AXIS));
        kok.add(sol);

        // etiketler
        JLabel jl1 = new JLabel("Fahrenheit:");
        jl1.setPreferredSize(new Dimension(100,20));
        jl1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        JLabel jl2 = new JLabel("Celsius:");
        jl2.setPreferredSize(new Dimension(100,20));
        jl2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        sol.add(jl1);
        sol.add(jl2);

        // sol dugme
        JButton fc = new JButton("C-F");
        fc.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                double c = Double.parseDouble(jt2.getText());
                c = c * 9.0/5.0 + 32;
                jt1.setText(Double.toString(c));
            }
        });

        sol.add(fc);

        // sag sutun
        JPanel sag = new JPanel();
        sag.setLayout(new BoxLayout(sag, BoxLayout.Y_AXIS));
        kok.add(sag);

        // metin kutulari
        jt1 = new JTextField();
        jt1.setPreferredSize(new Dimension(80,20));

        jt2 = new JTextField();
        jt2.setPreferredSize(new Dimension(80,20));

        sag.add(jt1);
        sag.add(jt2);

        // sag dugme
        JButton fc2 = new JButton("F-C");
        sag.add(fc2);

        this.pack();
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new Main();
    }

}

Hiç yorum yok:

Yorum Gönder