多平台统一管理软件接口,如何实现多平台统一管理软件接口
967
2022-12-31
本文目录一览:
耐心点,我帮你研究研究,嘿嘿……这样行不,可以请采纳!
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class JComboBoxTest {
private Book[] book = {new Book("《C++》","计算机编程语言","清华出版社","33.8"),new Book("《Java》","计算机编程语言","北京出版社","58.3"),
new Book("《JaveWeb》","web编程","工业出版社","23.5"),new Book("《c语言》","计算机基础","青年出版社","46.8"),new Book("《asp.net》","网页编程","新华出版社","60.5")};
private String[] str = {"C++","Java","JavaWeb","C语言","asp.net"};
private JComboBox jcb = new JComboBox(str);
private JFrame frame = new JFrame("welcome");
private JPanel pan1 = new JPanel();
private JPanel pan2 = new JPanel();
private JPanel pan3 = new JPanel();
private JPanel pan4 = new JPanel();
private JPanel pan5 = new JPanel();
private JTextField nameText = new JTextField();
private JTextField countText = new JTextField();
private JTextField resultText = new JTextField();
private JButton btn = new JButton("结账");
private JLabel lab = new JLabel("书店收银系统");
public JComboBoxTest(){
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(1);
}
});
jcb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jcb){
nameText.setText("书名:"+book[jcb.getSelectedIndex()].getBookName()+" 出版社:"+
book[jcb.getSelectedIndex()].getMakerName()+" 简介:"+book[jcb.getSelectedIndex()].getInfo()+" 价格:"+
book[jcb.getSelectedIndex()].getPrice());
}
}
});
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
if(e.getSource()==btn){
int count = Integer.parseInt(countText.getText());
float price = Float.parseFloat(book[jcb.getSelectedIndex()].getPrice());
float result = count*price;
resultText.setText("总价格为:"+result);
}
} catch (Exception e2) {
countText.setText("请输入购买数量!");
resultText.setText("");
}
}
});
jcb.setSelectedIndex(4);
frame.setLayout(new GridLayout(5,1));
pan1.setLayout(new GridLayout(1, 1));
pan2.setLayout(new GridLayout(1,1));
pan3.setLayout(new GridLayout(1, 1));
pan4.setLayout(new GridLayout(1, 1));
pan5.setLayout(new GridLayout(1, 1));
pan1.add(jcb);
pan2.add(nameText);
pan3.add(countText);
pan3.add(btn);
pan4.add(lab);
pan5.add(resultText);
frame.add(pan4);
frame.add(pan1);
frame.add(pan2);
frame.add(pan3);
frame.add(pan5);
frame.setSize(500,230);
frame.setLocation(500, 300);
frame.setVisible(true);
}
public static void main(String[] args) {
new JComboBoxTest();
}
}
class Book{
private String bookName;
private String info;
private String makerName;
private String price;
public Book(String bookName, String info, String makerName, String price) {
super();
this.bookName = bookName;
this.info = info;
this.makerName = makerName;
this.price = price;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getMakerName() {
return makerName;
}
public void setMakerName(String makerName) {
this.makerName = makerName;
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~