Arkadaşlar uzatmamak amacıyla Projemizi Main fonksiyonu içine yazdık.
İşte örnek uygulama;
import java.awt.GridLayout;
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.JOptionPane;
import javax.swing.JPanel;
public class Run {
public static void main(String[] args) {
JFrame pencere = new JFrame("Burçlar");
JPanel panel = new JPanel(new GridLayout(3, 2));
String[] aylar = { "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim",
"Kasım", "Aralık" };
JLabel ayJLabel = new JLabel("Ay:", JLabel.RIGHT);
panel.add(ayJLabel);
JComboBox ayBox = new JComboBox(aylar);
panel.add(ayBox);
JLabel gunJLabel = new JLabel("Gün:", JLabel.RIGHT);
panel.add(gunJLabel);
int gunler = 31;
Integer[] gunlerDizi = new Integer[gunler];
int inc = 1;
for (int i = 0; i < gunler; i++) {
gunlerDizi[i] = inc;
inc++;
}
final JComboBox<Integer> gunlerBox = new JComboBox<>(gunlerDizi);
panel.add(gunlerBox);
JButton hesaplaButton = new JButton("Hesapla");
panel.add(hesaplaButton);
hesaplaButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int gunler = (int) gunlerBox.getSelectedItem();
String aylar = (String) ayBox.getSelectedItem();
if (gunler >= 22 && ayBox.getSelectedItem() == "Aralık"
|| gunler <= 21 && ayBox.getSelectedItem() == "Ocak")
{
JOptionPane.showMessageDialog(null, "Burcunuz Oğlak");
}
else if (gunler >= 22 && ayBox.getSelectedItem() == "Ocak"
|| gunler <= 19 && ayBox.getSelectedItem() == "Şubat")
{
JOptionPane.showMessageDialog(null, "Burcunuz Kova");
}
else if (gunler >= 20 && ayBox.getSelectedItem() == "Şubat"
|| gunler <= 20 && ayBox.getSelectedItem() == "Mart")
{
JOptionPane.showMessageDialog(null, "Burcunuz Balık");
}
else if (gunler >= 21 && ayBox.getSelectedItem() == "Mart"
|| gunler <= 20 && ayBox.getSelectedItem() == "Nisan")
{
JOptionPane.showMessageDialog(null, "Burcunuz Oğlak");
}
else if (gunler >= 21 && ayBox.getSelectedItem() == "Nisan"
|| gunler <= 21 && ayBox.getSelectedItem() == "Mayıs")
{
JOptionPane.showMessageDialog(null, "Burcunuz Boğa");
}
else if (gunler >= 22 && ayBox.getSelectedItem() == "Mayıs"
|| gunler <= 22 && ayBox.getSelectedItem() == "Haziran")
{
JOptionPane.showMessageDialog(null, "Burcunuz İkizler");
}
else if (gunler >= 23 && ayBox.getSelectedItem() == "Haziran"
|| gunler <= 22 && ayBox.getSelectedItem() == "Temmuz")
{
JOptionPane.showMessageDialog(null, "Burcunuz Yengeç");
}
else if (gunler >= 23 && ayBox.getSelectedItem() == "Temmuz"
|| gunler <= 22 && ayBox.getSelectedItem() == "Ağustos")
{
JOptionPane.showMessageDialog(null, "Burcunuz Aslan");
}
else if (gunler >= 23 && ayBox.getSelectedItem() == "Ağustos"
|| gunler <= 22 && ayBox.getSelectedItem() == "Eylül")
{
JOptionPane.showMessageDialog(null, "Burcunuz Başak");
}
else if (gunler >= 23 && ayBox.getSelectedItem() == "Eylül"
|| gunler <= 22 && ayBox.getSelectedItem() == "Ekim")
{
JOptionPane.showMessageDialog(null, "Burcunuz Terazi");
}
else if (gunler >= 23 && ayBox.getSelectedItem() == "Ekim"
|| gunler <= 21 && ayBox.getSelectedItem() == "Kasım")
{
JOptionPane.showMessageDialog(null, "Burcunuz Akrep");
}
else {
JOptionPane.showMessageDialog(null, "Burcunuz Yay");
}
}
});
pencere.add(panel);
pencere.pack();
pencere.setVisible(true);
pencere.setLocationRelativeTo(null);
pencere.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Hiç yorum yok:
Yorum Gönder