📄 frame11.java
字号:
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;
import java.rmi.Naming;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Frame11 extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JTextField jTextField = null;
private JLabel jLabel2 = null;
private JPasswordField jPasswordField = null;
private JLabel jLabel3 = null;
private JTextField jTextField1 = null;
private JLabel jLabel4 = null;
private JLabel jLabel5 = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JLabel jLabel6 = null;
private JLabel jLabel7 = null;
private String account = null;
private String pin = null;
private String url = null; // @jve:decl-index=0:
private boolean isconnected = false;
private CommunityServerInterface thecommunity;
private JLabel jLabel8 = null;
/**
* This is the default constructor
*/
public Frame11() {
super();
initialize();
}
public Frame11(String Account, String Pin, String Url) {
super();
account = Account;
pin = Pin;
url = Url;
initializeRMI();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(587, 200);
this.setContentPane(getJContentPane());
this.setTitle("转账");
this.setVisible(true);
}
private double findbalance() {
try {
double temp = thecommunity.findbalance(account, pin);
return temp;
} catch (Exception ex) {
System.out.println(ex);
return -1;
}
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel8 = new JLabel();
jLabel8.setBounds(new Rectangle(360, 76, 77, 28));
jLabel8.setText("向该帐户:");
jLabel7 = new JLabel();
jLabel7.setBounds(new Rectangle(360, 31, 77, 30));
jLabel7.setText("从该帐户:");
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(299, 106, 152, 18));
jLabel6.setText("当前只提供人民币交易。");
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(121, 135, 165, 18));
jLabel5.setText("¥" + String.valueOf(findbalance()));
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(16, 136, 90, 18));
jLabel4.setText("本帐户金额:");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(16, 106, 90, 18));
jLabel3.setText("交易金额:");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(15, 75, 91, 18));
jLabel2.setText("帐号密码;");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(15, 46, 92, 19));
jLabel1.setText("对方帐号:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(5, 3, 342, 34));
jLabel.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel.setIcon(new ImageIcon(getClass().getResource("/ball.jpg")));
jLabel.setText("欢迎使用网上银行,ATM转账功能!");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(getJTextField(), null);
jContentPane.add(jLabel2, null);
jContentPane.add(getJPasswordField(), null);
jContentPane.add(jLabel3, null);
jContentPane.add(getJTextField1(), null);
jContentPane.add(jLabel4, null);
jContentPane.add(jLabel5, null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(getJButton2(), null);
jContentPane.add(jLabel6, null);
jContentPane.add(jLabel7, null);
jContentPane.add(jLabel8, null);
}
return jContentPane;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(120, 46, 164, 22));
}
return jTextField;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(120, 75, 165, 22));
}
return jPasswordField;
}
/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(new Rectangle(121, 105, 165, 22));
jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
// System.out.println("keyPressed()");
if((e.getKeyCode()<e.VK_0||e.getKeyCode()>e.VK_9)&&(e.getKeyCode()!=e.VK_PERIOD)&&(e.getKeyCode()!=e.VK_BACK_SPACE)&&(e.getKeyCode()<e.VK_NUMPAD0||e.getKeyCode()>e.VK_NUMPAD9)&&(e.getKeyCode()!=e.VK_DELETE))
{
JOptionPane.showMessageDialog(null,"请输入数字","警告",JOptionPane.WARNING_MESSAGE);
}// TODO Auto-generated Event stub keyPressed()
}
});
}
return jTextField1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(450, 31, 74, 29));
jButton.setText("转入");
jButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButtonActionPerformed(evt);
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(451, 75, 74, 30));
jButton1.setText("转出");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
}
return jButton1;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(new Rectangle(451, 120, 76, 29));
jButton2.setText("取消");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
}
return jButton2;
}
private void jButton2ActionPerformed(ActionEvent evt) {
// System.out.println("jButton2.actionPerformed, event=" + evt);
this.setVisible(false);
// TODO add your code for jButton2.actionPerformed
}
private void jButton1ActionPerformed(ActionEvent evt) {
// System.out.println("jButton1.actionPerformed, event=" + evt);
String itsaccount = jTextField.getText();
String itspin = new String(jPasswordField.getPassword());
String pin0 = jTextField1.getText();
double num = Double.parseDouble(pin0);
try {
if (num <= 0) {
JOptionPane.showMessageDialog(null,
"Please enter righter number", "Message error",
JOptionPane.ERROR_MESSAGE);
} else if (thecommunity.getpermission(itsaccount, itspin, "Bank")) {
if (thecommunity.withdraw(account, pin, num)
&& thecommunity.deposit(itsaccount, itspin, num)) {
jLabel5.setText("¥" + String.valueOf(findbalance()));
jTextField.setText("");
jPasswordField.setText("");
jTextField1.setText("");
JOptionPane
.showMessageDialog(
null,
"Your have succeed in turn money out of your account!",
"Turn out money", JOptionPane.OK_OPTION);
} else
JOptionPane.showMessageDialog(null,
"Overdraft error, please retry!", "Message error",
JOptionPane.ERROR_MESSAGE);
} else
JOptionPane.showMessageDialog(null,
"The other Account isn\'t exist!", "Message error",
JOptionPane.ERROR_MESSAGE);
} catch (Exception ex) {
System.out.println(ex);
JOptionPane.showMessageDialog(null,
"The net is busy, please retry!", "Message error",
JOptionPane.ERROR_MESSAGE);
}
// TODO add your code for jButton1.actionPerformed
}
private void jButtonActionPerformed(ActionEvent evt) {
// System.out.println("jButton.actionPerformed, event=" + evt);
String itsaccount = jTextField.getText();
String itspin = new String(jPasswordField.getPassword());
String pin0 = jTextField1.getText();
double num = Double.parseDouble(pin0);
try {
if (num <= 0) {
JOptionPane.showMessageDialog(null,
"Please enter righter number", "Message error",
JOptionPane.ERROR_MESSAGE);
} else if (thecommunity.getpermission(account, pin, "Bank")) {
if (thecommunity.withdraw(itsaccount, itspin, num)
&& thecommunity.deposit(account, pin, num)) {
jLabel5.setText("¥" + String.valueOf(findbalance()));
jTextField.setText("");
jPasswordField.setText("");
jTextField1.setText("");
JOptionPane
.showMessageDialog(
null,
"Your have succeed in turn money into your account!",
"Turn in money", JOptionPane.OK_OPTION);
} else
JOptionPane.showMessageDialog(null,
"Overdraft error, please retry!", "Message error",
JOptionPane.ERROR_MESSAGE);
} else
JOptionPane.showMessageDialog(null,
"The other Account isn\'t exist!", "Message error",
JOptionPane.ERROR_MESSAGE);
} catch (Exception ex) {
System.out.println(ex);
JOptionPane.showMessageDialog(null,
"The net is busy, please retry!", "Message error",
JOptionPane.ERROR_MESSAGE);
}
// TODO add your code for jButton.actionPerformed
}
protected boolean initializeRMI() {
if (isconnected)
return true;
if (url.equals("default"))
url = "";
// url = "rmi://"+url+"/";
try {
thecommunity = (CommunityServerInterface) Naming.lookup(url
+ "CommunityServerInterfaceImpl");
System.out.println("Server object " + thecommunity + " found");
isconnected = true;
return true;
} catch (Exception ex) {
System.out.println(url);
System.out.println(ex);
JOptionPane.showMessageDialog(null, "Please enter right ID!",
"ID error", JOptionPane.ERROR_MESSAGE);
return false;
}
}
} // @jve:decl-index=0:visual-constraint="77,36"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -