📄 sellshoepopup.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class SellShoePopup
extends MouseAdapter
implements ActionListener {
private JPopupMenu menu = new JPopupMenu("Table Options");
Icon icondel=new ImageIcon("delete.jpg");
Icon iconadd=new ImageIcon("add.jpg");
Icon iconmod=new ImageIcon("mod.jpg");
Icon iconext=new ImageIcon("ext.jpg");
Icon iconabt=new ImageIcon("abt.jpg");
private JMenuItem add = new JMenuItem(" 添加项目",iconadd);
private JMenuItem del = new JMenuItem("删除项目",icondel);
private JMenuItem mod = new JMenuItem("修改项目",iconmod);
private JMenuItem ext = new JMenuItem("退出系统",iconext);
private JMenuItem abt = new JMenuItem("关于系统",iconabt);
private SellShoe parent = null;
public SellShoePopup(SellShoe _parent) {
parent = _parent;
menu.add(add);
add.addActionListener(this);
menu.add(new JPopupMenu.Separator());
menu.add(mod);
mod.addActionListener(this);
menu.add(new JPopupMenu.Separator());
menu.add(del);
del.addActionListener(this);
menu.add(new JPopupMenu.Separator());
menu.add(ext);
ext.addActionListener(this);
menu.add(new JPopupMenu.Separator());
menu.add(abt);
abt.addActionListener(this);
}
public void mousePressed(MouseEvent me) {
if (SwingUtilities.isRightMouseButton(me)) {
menu.show(parent.table, me.getX(), me.getY());
}
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == add) {
add();
}
else if (ae.getSource() == del) {
delete();
}
else if (ae.getSource() == mod) {
modify();
}
else if (ae.getSource() == ext) {
ext();
}
else if (ae.getSource() == abt) {
abt();
}
}
private void delete() {
/*从表格中删除当前选择的行*/
int row = parent.table.getSelectedRow();
if (row >= 0) {
String msg = "删除 '" + parent.data.getValueAt(row, 0) + "'号"+ parent.data.getValueAt(row, 1) + "色?";
if (JOptionPane.showConfirmDialog(parent, msg, "删除项目",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE)
== JOptionPane.YES_OPTION) {
parent.data.removeRow(row);
parent.price.setText("总的价钱: ¥" + parent.total());
}
}
}
private void add() {
/*弹出对话框,以便在表格中增加支票项*/
SellShoePanel sellshoe = new SellShoePanel();
if (JOptionPane.showOptionDialog(parent, sellshoe, "添加项目",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, null, null) ==
JOptionPane.YES_OPTION) {
try {
parent.data.addRow(sellshoe.getData());
parent.price.setText("总的价钱: ¥" + parent.total());
}
catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(parent, "数据不能为空!",
"错误信息",
JOptionPane.ERROR_MESSAGE);
}
}
}
private void ext(){
/*退出表单系统 */
System.exit(0);
}
private void abt(){
/* 关于表单系统*/
JOptionPane.showMessageDialog(null, "auther:刘红 timer:2005年7月15日 ",
"about:售鞋表单系统", JOptionPane.PLAIN_MESSAGE);
}
private void modify() {
/*弹出包含一个发票项的对话框,进行编辑。*/
SellShoePanel sellshoe = new SellShoePanel();
int row = parent.table.getSelectedRow();
if (row >= 0) {
String data[] = new String[4];
for (int i = 0; i < data.length; i++) {
data[i] = parent.data.getValueAt(row, i).toString();
}
sellshoe.setData(data);
if (JOptionPane.showOptionDialog(parent, sellshoe, "修改项目",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE,
null, null, null) ==
JOptionPane.YES_OPTION) {
try {
for (int i = 0; i < sellshoe.getData().length; i++) {
parent.data.setValueAt(sellshoe.getData()[i], row, i);
}
parent.price.setText("总的价钱: ¥" + parent.total());
}
catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(parent, "数据不能为空",
"错误信息",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -