📄 mains.java
字号:
package com.rtsoft.calc;
import java.awt.ComponentOrientation;
import java.awt.Dialog.ModalExclusionType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import com.rtsoft.calc.action.CalcAction;
import com.rtsoft.calc.util.StringUtil;
public class Mains extends JFrame {
private JTextField box;
private JTextField end_id;
private JTextField go_id;
private JTextField end_mac;
private JTextField go_mac;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
try {
Mains frame = new Mains();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the frame
*/
public Mains() {
super();
getContentPane().setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
setTitle("支付通算号器");
getContentPane().setLayout(null);
this.setResizable(false);
setBounds(380, 250, 500, 375);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final JLabel label = new JLabel();
label.setText("开始MAC地址号:");
label.setBounds(39, 10, 109, 25);
getContentPane().add(label);
final JLabel label_1 = new JLabel();
label_1.setText("生成MAC号个数:");
label_1.setBounds(39, 72, 109, 15);
getContentPane().add(label_1);
go_mac = new JTextField();
go_mac.setBounds(154, 26, 189, 23);
getContentPane().add(go_mac);
end_mac = new JTextField();
end_mac.setBounds(154, 65, 189, 25);
getContentPane().add(end_mac);
final JLabel over_mac = new JLabel();
over_mac.setHorizontalAlignment(SwingConstants.CENTER);
over_mac.setText("确认开始MAC地址无误后点击生成自动生成MAC号!");
over_mac.setBounds(91, 120, 335, 25);
getContentPane().add(over_mac);
final JButton button_mac = new JButton();
button_mac.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!(StringUtil.isMacGo(go_mac.getText())).equals("success")) {
JOptionPane.showMessageDialog(null, StringUtil
.isMacGo(go_mac.getText()), "MAC格式不正确!",
JOptionPane.ERROR_MESSAGE);
return;
}
if (!(StringUtil.isMacNo(end_mac.getText())).equals("success")) {
JOptionPane.showMessageDialog(null, StringUtil
.isMacNo(end_mac.getText()), "MAC号个数不正确!",
JOptionPane.ERROR_MESSAGE);
return;
}
try {
if (!CalcAction.saveMac(go_mac.getText(), Integer
.parseInt(end_mac.getText()))) {
JOptionPane.showMessageDialog(null, "写入MAC到文件失败!",
"错误!!", JOptionPane.ERROR_MESSAGE);
return;
}
} catch (Exception ee) {
ee.printStackTrace();
JOptionPane.showMessageDialog(null, ee.getMessage(), "错误!",
JOptionPane.ERROR_MESSAGE);
return;
}
JOptionPane.showMessageDialog(null, "MAC写入成功!", "恭喜!",
JOptionPane.OK_CANCEL_OPTION);
go_mac.setText("");
end_mac.setText("");
}
});
button_mac.setText("生 成");
button_mac.setBounds(366, 68, 99, 23);
getContentPane().add(button_mac);
final JLabel label_2 = new JLabel();
label_2.setText("开始ID号:");
label_2.setBounds(39, 194, 60, 15);
getContentPane().add(label_2);
final JLabel label_2_1 = new JLabel();
label_2_1.setText("ID号个数:");
label_2_1.setBounds(39, 232, 60, 15);
getContentPane().add(label_2_1);
go_id = new JTextField();
go_id.setBounds(154, 191, 189, 21);
getContentPane().add(go_id);
end_id = new JTextField();
end_id.setBounds(154, 229, 189, 21);
getContentPane().add(end_id);
final JButton button_id = new JButton();
button_id.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(box.getText().equals("")||box.getText().length()>7){
JOptionPane
.showMessageDialog(null, "箱号格式不正确!长度不能大于7!", "箱号格式不正确!",JOptionPane.ERROR_MESSAGE);
return;
}
if (!(StringUtil.isNoGo(go_id.getText())).equals("success")) {
JOptionPane
.showMessageDialog(null, StringUtil.isNoGo(go_id
.getText()), "终端号格式不正确!",
JOptionPane.ERROR_MESSAGE);
return;
}
if (!(StringUtil.isNoNo(end_id.getText())).equals("success")) {
JOptionPane.showMessageDialog(null, StringUtil
.isNoGo(end_id.getText()), "终端号个数不正确!",
JOptionPane.ERROR_MESSAGE);
return;
}
// 批量写入ID号
try {
if (!CalcAction.saveId(Long.parseLong(go_id.getText()),Long.parseLong(end_id.getText()),box.getText())) {
JOptionPane.showMessageDialog(null, "写入ID到文件失败!",
"错误!!", JOptionPane.ERROR_MESSAGE);
return;
}
} catch (Exception ee) {
ee.printStackTrace();
JOptionPane.showMessageDialog(null, ee.getMessage(), "错误!",
JOptionPane.ERROR_MESSAGE);
return;
}
JOptionPane.showMessageDialog(null, "终端ID号写入成功!", "恭喜!",
JOptionPane.OK_CANCEL_OPTION);
go_id.setText("");
end_id.setText("");
box.setText("");
}
});
button_id.setText("生 成");
button_id.setBounds(382, 228, 99, 23);
getContentPane().add(button_id);
final JButton button_mac_file = new JButton();
button_mac_file.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
Runtime.getRuntime().exec("c:/windows/notepad.exe Mac.txt");;
}catch(Exception ee){
ee.printStackTrace();
JOptionPane.showMessageDialog(null, ee.getMessage(), "错误!",
JOptionPane.ERROR_MESSAGE);
}
}
});
button_mac_file.setText("查看生成MAC");
button_mac_file.setBounds(91, 287, 129, 23);
getContentPane().add(button_mac_file);
final JButton button_id_file = new JButton();
button_id_file.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
Runtime.getRuntime().exec("c:/windows/notepad.exe Id.txt");;
}catch(Exception ee){
ee.printStackTrace();
JOptionPane.showMessageDialog(null, ee.getMessage(), "错误!",
JOptionPane.ERROR_MESSAGE);
}
}
});
button_id_file.setText("查看生成ID");
button_id_file.setBounds(273, 287, 121, 23);
getContentPane().add(button_id_file);
final JSeparator separator = new JSeparator();
separator.setBounds(0, 159, 492, 15);
getContentPane().add(separator);
box = new JTextField();
box.setBounds(382, 191, 99, 21);
getContentPane().add(box);
final JLabel label_3 = new JLabel();
label_3.setText("箱号:");
label_3.setBounds(349, 194, 44, 15);
getContentPane().add(label_3);
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -