29 05 2014
2. soru ve yanıtı
import java.awt.EventQueue;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ButtonGroup;
import java.awt.Color;
import java.awt.Font;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
public class UrunSatis {
private JFrame frmrnSat;
private JTextField txtUrunAdi;
private JTextField txtUrunFiyati;
private JTextField txtUrun;
private JTextField txtToplam;
private final ButtonGroup buttonGroup = new ButtonGroup();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UrunSatis window = new UrunSatis();
window.frmrnSat.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public UrunSatis() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmrnSat = new JFrame();
frmrnSat.setTitle(“\u00DCr\u00FCn Sat\u0131\u015F”);
frmrnSat.setBounds(100, 100, 544, 300);
frmrnSat.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmrnSat.getContentPane().setLayout(null);
JLabel lblUrunAd = new JLabel(“\u00DCr\u00FCn Ad\u0131:”);
lblUrunAd.setBounds(17, 11, 89, 14);
frmrnSat.getContentPane().add(lblUrunAd);
JLabel ıblUrunFiyat = new JLabel(“\u00DCr\u00FCn Fiyat\u0131:”);
ıblUrunFiyat.setBounds(17, 36, 89, 14);
frmrnSat.getContentPane().add(ıblUrunFiyat);
JLabel lblKdv = new JLabel(“KDV Oran\u0131”);
lblKdv.setBounds(17, 61, 69, 14);
frmrnSat.getContentPane().add(lblKdv);
final JRadioButton radioOgrenci = new JRadioButton(“\u00D6\u011Frenci”);
radioOgrenci.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent arg0)
{
// if(radioOgrenci.isSelected())
// txtToplam.setText(String.valueOf(KDV_liFiyat*0.9));
}
});
buttonGroup.add(radioOgrenci);
radioOgrenci.setBounds(302, 11, 86, 23);
frmrnSat.getContentPane().add(radioOgrenci);
final JRadioButton radioTam = new JRadioButton(“Tam”);
radioTam.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent arg0)
{
// if(radioTam.isSelected())
// txtToplam.setText(String.valueOf(KDV_liFiyat));
}
});
radioTam.setSelected(true);
buttonGroup.add(radioTam);
radioTam.setBounds(302, 37, 69, 23);
frmrnSat.getContentPane().add(radioTam);
JLabel lblIskonto = new JLabel(“\u0130skonto”);
lblIskonto.setBounds(247, 15, 49, 14);
frmrnSat.getContentPane().add(lblIskonto);
JLabel lblUrun = new JLabel(“\u00DCr\u00FCn”);
lblUrun.setBounds(17, 136, 69, 14);
frmrnSat.getContentPane().add(lblUrun);
JLabel lblToplamTutar = new JLabel(“Toplam Tutar”);
lblToplamTutar.setBounds(17, 165, 86, 14);
frmrnSat.getContentPane().add(lblToplamTutar);
txtUrunAdi = new JTextField();
txtUrunAdi.setBounds(116, 8, 106, 20);
frmrnSat.getContentPane().add(txtUrunAdi);
txtUrunAdi.setColumns(10);
txtUrunFiyati = new JTextField();
txtUrunFiyati.setBounds(116, 33, 106, 20);
frmrnSat.getContentPane().add(txtUrunFiyati);
txtUrunFiyati.setColumns(10);
txtUrun = new JTextField();
txtUrun.setBounds(116, 133, 86, 20);
frmrnSat.getContentPane().add(txtUrun);
txtUrun.setColumns(10);
txtToplam = new JTextField();
txtToplam.setBounds(116, 162, 137, 20);
frmrnSat.getContentPane().add(txtToplam);
txtToplam.setColumns(10);
final JLabel lblMesaj = new JLabel(“”);
lblMesaj.setFont(new Font(“Tahoma”, Font.PLAIN, 13));
lblMesaj.setForeground(Color.RED);
lblMesaj.setBounds(125, 210, 263, 14);
frmrnSat.getContentPane().add(lblMesaj);
final JComboBox comboKdv = new JComboBox();
comboKdv.setBounds(116, 58, 55, 20);
frmrnSat.getContentPane().add(comboKdv);
String[] dizi = new String[2];
dizi[0] = “8”;
dizi[1] = “18”;
ComboBoxModel comboModel = new DefaultComboBoxModel(dizi);
comboKdv.setModel(comboModel);
JButton btnHesapla = new JButton(“Hesapla”);
btnHesapla.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
lblMesaj.setText(null);
if(!txtUrunAdi.getText().isEmpty() && !txtUrunFiyati.getText().isEmpty())
{
String UrunAdi = txtUrunAdi.getText();
double urunFiyat=Double.parseDouble(txtUrunFiyati.getText());
//double KDV_liFiyat=urunFiyat+(urunFiyat*(Integer.parseInt(comboKdv.getSelectedItem().toString()))/100);
int KDV_Orani=Integer.parseInt(comboKdv.getSelectedItem().toString());
double KDV_liFiyat=(urunFiyat*KDV_Orani/100)+urunFiyat;
if(radioOgrenci.isSelected())
txtToplam.setText(String.valueOf(KDV_liFiyat*0.9));
else
txtToplam.setText(String.valueOf(KDV_liFiyat));
txtUrun.setText(UrunAdi);
}
else
lblMesaj.setText(“Boş alan bırakmayınız!”);
}
});
btnHesapla.setBounds(116, 101, 89, 23);
frmrnSat.getContentPane().add(btnHesapla);
JLabel label = new JLabel(“(%10)”);
label.setBounds(403, 10, 46, 14);
frmrnSat.getContentPane().add(label);
JLabel label_1 = new JLabel(“(%0)”);
label_1.setBounds(403, 36, 46, 14);
frmrnSat.getContentPane().add(label_1);
}
}
1.soru ve yanıtı Oto Fiyat Hesaplama