j2ee ejb编程实例.j2ee ejb编程实例.

源代码在线查看: mainframe.java~71~

软件大小: 616 K
上传用户: makai1630
关键词: ejb j2ee 编程实例 ee
下载地址: 免注册下载 普通下载 VIP

相关代码

				package calculatebean;								import java.awt.*;				import com.borland.jbcl.layout.*;				import javax.swing.*;				import javax.swing.border.*;				import java.awt.event.*;				import java.beans.*;				import java.util.*;								//public class MainFrame extends JFrame				public class MainFrame extends JFrame implements PropertyChangeListener				{				  XYLayout xYLayout1 = new XYLayout();				  Border border1;				  Border border2;				  Border border3;				  Border border4;				  Border border5;				  Border border6;				  Border border7;				  Border border8;				  Border border9;				  Border border10;				  Border border11;				  Border border12;				  Border border13;				  Border border14;				  Border border15;				  Border border16;				  Border border17;				  TitledBorder titledBorder1;				  TitledBorder titledBorder2;				  TitledBorder titledBorder3;				  TitledBorder titledBorder4;				  TitledBorder titledBorder5;				  JPanel jPanel1 = new JPanel();				  XYLayout xYLayout2 = new XYLayout();				  JLabel jLabel2 = new JLabel();				  JLabel jLabel3 = new JLabel();				  JLabel jLabel4 = new JLabel();				  JLabel jLabel5 = new JLabel();				  JLabel jLabel6 = new JLabel();				  JLabel jLabel7 = new JLabel();				  JTextField jTextField1 = new JTextField();				  JTextField jTextField2 = new JTextField();				  JPanel jPanel2 = new JPanel();				  XYLayout xYLayout3 = new XYLayout();				  JButton jButton1 = new JButton();				  JButton jButton2 = new JButton();				  JButton jButton3 = new JButton();				  JButton jButton4 = new JButton();				  JPanel jPanel3 = new JPanel();				  JLabel jLabel1 = new JLabel();				  JButton jButton5 = new JButton();				  JButton jButton6 = new JButton();				  XYLayout xYLayout4 = new XYLayout();				  ResultLabelBean resultlabelbean = new ResultLabelBean();  // 实例化ResultLabelBean				  inputValueBean inputvaluebean = new inputValueBean();     // 实例化inputValueBean				  CalculateResultBean calculateresultbean = new CalculateResultBean();    // 实例化CalculateResultBean				  String x_inputvalue = null;				  String y_inputvalue = null;				  int x_inputValue = 0;   // 存放输入的x的值				  int y_inputValue = 0;   // 存放输入的y的值				  String choose_opValue = null;   // 存放所选择的运算符												  public MainFrame()				  {				    try				    {				      jbInit();				    }				    catch(Exception e)				    {				      e.printStackTrace();				    }				  }				  public static void main(String[] args)				  {				    MainFrame mainFrame = new MainFrame();				    mainFrame.setLocation(150,80);				    mainFrame.setSize(421,363);				    mainFrame.show();				  }				  private void jbInit() throws Exception				  {				    border1 = BorderFactory.createCompoundBorder(new TitledBorder(BorderFactory.createLineBorder(new Color(13, 210, 151),1),"输入数值"),BorderFactory.createEmptyBorder(1,1,1,1));				    border2 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(SystemColor.controlText,1),BorderFactory.createEmptyBorder(1,1,1,1));				    border3 = BorderFactory.createCompoundBorder(new TitledBorder(BorderFactory.createLineBorder(Color.blue,2),"输入计算的数值"),BorderFactory.createEmptyBorder(1,1,1,1));				    border4 = BorderFactory.createLineBorder(SystemColor.controlText,1);				    titledBorder1 = new TitledBorder(border4,"输入计算的数值");				    border5 = BorderFactory.createCompoundBorder(new TitledBorder(BorderFactory.createLineBorder(Color.blue,1),"输入计算的数值"),BorderFactory.createEmptyBorder(1,1,1,1));				    border6 = BorderFactory.createLineBorder(Color.blue,1);				    titledBorder2 = new TitledBorder(border6,"输入计算的数值");				    border7 = BorderFactory.createCompoundBorder(titledBorder2,BorderFactory.createEmptyBorder(1,1,1,1));				    border8 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(SystemColor.desktop,1),BorderFactory.createEmptyBorder(1,1,1,1));				    border9 = BorderFactory.createLineBorder(Color.blue,1);				    titledBorder3 = new TitledBorder(border9,"选择运算符");				    border10 = BorderFactory.createCompoundBorder(titledBorder3,BorderFactory.createEmptyBorder(1,1,1,1));				    border11 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(SystemColor.desktop,1),BorderFactory.createEmptyBorder(1,1,1,1));				    border12 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.magenta,1),BorderFactory.createEmptyBorder(1,1,1,1));				    border13 = BorderFactory.createLineBorder(new Color(230, 131, 105),1);				    titledBorder4 = new TitledBorder(border13,"运行结果");				    border14 = BorderFactory.createCompoundBorder(titledBorder4,BorderFactory.createEmptyBorder(1,1,1,1));				    border15 = BorderFactory.createLineBorder(Color.magenta,1);				    titledBorder5 = new TitledBorder(border15,"运行结果");				    border16 = BorderFactory.createCompoundBorder(titledBorder5,BorderFactory.createEmptyBorder(1,1,1,1));				    border17 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(new Color(72, 210, 164),1),BorderFactory.createEmptyBorder(1,1,1,1));				    this.getContentPane().setBackground(SystemColor.info);				    this.setTitle("一个关于计算的JavaBean的演示");				    this.getContentPane().setLayout(xYLayout1);				    xYLayout1.setWidth(410);				    xYLayout1.setHeight(337);				    jPanel1.setBackground(SystemColor.info);				    jPanel1.setBorder(border7);				    jPanel1.setLayout(xYLayout2);				    jLabel2.setText("输入 x 的值为:");				    jLabel3.setText("输入 y 的值为:");				    jTextField1.setBorder(border8);				    jTextField1.addFocusListener(new MainFrame_jTextField1_focusAdapter(this));				    jTextField2.setBorder(border8);				    jTextField2.addFocusListener(new MainFrame_jTextField2_focusAdapter(this));				    jPanel2.setLayout(xYLayout3);				    jPanel2.setBackground(SystemColor.info);				    jPanel2.setBorder(border10);				    jButton1.setFont(new java.awt.Font("Dialog", 1, 15));				    jButton1.setBorder(border11);				    jButton1.setHorizontalTextPosition(SwingConstants.LEFT);				    jButton1.setText("+");				    jButton1.addActionListener(new MainFrame_jButton1_actionAdapter(this));				    jButton2.setText("-");				    jButton2.addActionListener(new MainFrame_jButton2_actionAdapter(this));				    jButton2.setHorizontalTextPosition(SwingConstants.LEFT);				    jButton2.setFont(new java.awt.Font("Dialog", 1, 15));				    jButton2.setBorder(border11);				    jButton3.setText("*");				    jButton3.addActionListener(new MainFrame_jButton3_actionAdapter(this));				    jButton3.setHorizontalTextPosition(SwingConstants.LEFT);				    jButton3.setBorder(border11);				    jButton3.setFont(new java.awt.Font("DialogInput", 1, 15));				    jButton4.setText("/");				    jButton4.addActionListener(new MainFrame_jButton4_actionAdapter(this));				    jButton4.setHorizontalTextPosition(SwingConstants.LEFT);				    jButton4.setBorder(border11);				    jButton4.setFont(new java.awt.Font("Dialog", 1, 15));				    jPanel3.setBackground(SystemColor.info);				    jPanel3.setBorder(border16);				    jPanel3.setLayout(xYLayout4);				    jLabel1.setFont(new java.awt.Font("Dialog", 0, 15));				    jLabel1.setBorder(border17);				    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);				    jLabel1.setText("一个关于计算的JavaBean");				    jButton5.setText("退    出");				    jButton5.addActionListener(new MainFrame_jButton5_actionAdapter(this));				    jLabel5.setText("未输入 x 的值");				    jLabel6.setText("未输入 y 的值");				//    jLabel7.setText("未选择任何运算符");				resultlabelbean.setText("未选择任何运算符");				    jLabel4.setText("还未输入 x 的值");				    jLabel5.setText("还未输入 y 的值");				    jLabel6.setText("还未选择任何运算符");				    jLabel7.setText("x op y = ?");				    jButton6.setText("运    算");				    jButton6.addActionListener(new MainFrame_jButton6_actionAdapter(this));				    this.getContentPane().add(jPanel1,     new XYConstraints(21, 58, 195, 128));				    jPanel1.add(jLabel2,   new XYConstraints(16, 16, -1, -1));				    jPanel1.add(jLabel3,   new XYConstraints(16, 50, -1, -1));				    jPanel1.add(jTextField1,        new XYConstraints(112, 18, 55, 18));				    jPanel1.add(jTextField2,    new XYConstraints(112, 53, 55, 18));				    this.getContentPane().add(jPanel2,         new XYConstraints(230, 58, 160, 129));				    jPanel2.add(jButton1, new XYConstraints(30, 12, 26, 25));				    jPanel2.add(jButton2, new XYConstraints(91, 12, 26, 25));				    jPanel2.add(jButton3, new XYConstraints(30, 61, 26, 25));				    jPanel2.add(jButton4, new XYConstraints(91, 61, 26, 25));				    this.getContentPane().add(jPanel3,  new XYConstraints(24, 196, 365, 88));				    jPanel3.add(jLabel5,     new XYConstraints(195, 0, 146, -1));				    jPanel3.add(jLabel4,   new XYConstraints(23, 0, 159, -1));				    jPanel3.add(jLabel7,    new XYConstraints(23, 43, 324, -1));				    jPanel3.add(jLabel6,       new XYConstraints(23, 22, 324, -1));				    this.getContentPane().add(jLabel1,  new XYConstraints(23, 18, 368, 32));				    this.getContentPane().add(jButton5,    new XYConstraints(303, 298, 81, 26));				    this.getContentPane().add(jButton6,    new XYConstraints(195, 299, 81, 26));				this.add(resultlabelbean,null);				resultlabelbean.addPropertyChangeListener(this);  // 注册本对象为resultlabelbean的事件变化监听器				  }								  void jButton5_actionPerformed(ActionEvent e)				  {				   /* 退出系统 */				   System.exit(0);				  }								  void jButton1_actionPerformed(ActionEvent e)				  {				   /* 执行加法运算 */				   choose_opValue = jButton1.getText();				   if(choose_opValue != null && choose_opValue.length() > 0)				     {				      choose_opValue = choose_opValue.trim();				      resultlabelbean.setOpValue(choose_opValue);   // 改变ResultLabelBean的属性				     }				  }								  void jButton2_actionPerformed(ActionEvent e)				  {				   /* 执行减法运算 */				   choose_opValue = jButton2.getText();				   if(choose_opValue != null && choose_opValue.length() > 0)				     {				      choose_opValue = choose_opValue.trim();				      resultlabelbean.setOpValue(choose_opValue);   // 改变ResultLabelBean的属性				     }				  }								  void jButton3_actionPerformed(ActionEvent e)				  {				   /* 执行乘法运算 */				   choose_opValue = jButton3.getText();				   if(choose_opValue != null && choose_opValue.length() > 0)				     {				      choose_opValue = choose_opValue.trim();				      resultlabelbean.setOpValue(choose_opValue);   // 改变ResultLabelBean的属性				     }				  }								  void jButton4_actionPerformed(ActionEvent e)				  {				   /* 执行除法运算 */				   choose_opValue = jButton4.getText();				   if(choose_opValue != null && choose_opValue.length() > 0)				     {				      choose_opValue = choose_opValue.trim();				      resultlabelbean.setOpValue(choose_opValue);   // 改变ResultLabelBean的属性				     }				  }								  void jButton6_actionPerformed(ActionEvent e)				  {				    /* 开始执行运算 */				    if(x_inputValue != -1 && y_inputValue != -1 && choose_opValue != null && choose_opValue.length() > 0)				      {				       calculateresultbean.setCalculateValue(choose_opValue,x_inputValue,y_inputValue);				      }				    else				      {				       JOptionPane.showMessageDialog(null,"请正确输入x和y的值,并且选择一个有效的运算符!","出错啦!",0);				      }				  }								  void jTextField1_focusLost(FocusEvent e)				  {				   /* 设置x的输入值 */				   x_inputvalue = jTextField1.getText();				   if(x_inputvalue != null && x_inputvalue.length() > 0)				     {				      try				        {				         x_inputvalue = x_inputvalue.trim();				         x_inputValue = Integer.parseInt(x_inputvalue);				         inputvaluebean.setInputValue_X(x_inputvalue);				        }				      catch(Exception err)				        {				         x_inputValue = -1;				         JOptionPane.showMessageDialog(null,"请正确输入一个整数!","出错啦!",0);				        }				     }				  }								  void jTextField2_focusLost(FocusEvent e)				  {				   /* 设置y的输入值 */				   y_inputvalue = jTextField2.getText();				   if(y_inputvalue != null && y_inputvalue.length() > 0)				     {				      try				        {				         y_inputvalue = y_inputvalue.trim();				         y_inputValue = Integer.parseInt(y_inputvalue);				         inputvaluebean.setInputValue_Y(y_inputvalue);				        }				      catch(Exception err)				        {				         y_inputValue = -1;				         JOptionPane.showMessageDialog(null,"请正确输入一个整数!","出错啦!",0);				        }				     }				  }				}								class MainFrame_jButton5_actionAdapter implements java.awt.event.ActionListener				{				  MainFrame adaptee;								  MainFrame_jButton5_actionAdapter(MainFrame adaptee)				  {				    this.adaptee = adaptee;				  }				  public void actionPerformed(ActionEvent e)				  {				    adaptee.jButton5_actionPerformed(e);				  }				}								class MainFrame_jButton1_actionAdapter implements java.awt.event.ActionListener				{				  MainFrame adaptee;								  MainFrame_jButton1_actionAdapter(MainFrame adaptee)				  {				    this.adaptee = adaptee;				  }				  public void actionPerformed(ActionEvent e)				  {				    adaptee.jButton1_actionPerformed(e);				  }				}								class MainFrame_jButton2_actionAdapter implements java.awt.event.ActionListener				{				  MainFrame adaptee;								  MainFrame_jButton2_actionAdapter(MainFrame adaptee)				  {				    this.adaptee = adaptee;				  }				  public void actionPerformed(ActionEvent e)				  {				    adaptee.jButton2_actionPerformed(e);				  }				}								class MainFrame_jButton3_actionAdapter implements java.awt.event.ActionListener				{				  MainFrame adaptee;								  MainFrame_jButton3_actionAdapter(MainFrame adaptee)				  {				    this.adaptee = adaptee;				  }				  public void actionPerformed(ActionEvent e)				  {				    adaptee.jButton3_actionPerformed(e);				  }				}								class MainFrame_jButton4_actionAdapter implements java.awt.event.ActionListener				{				  MainFrame adaptee;								  MainFrame_jButton4_actionAdapter(MainFrame adaptee)				  {				    this.adaptee = adaptee;				  }				  public void actionPerformed(ActionEvent e)				  {				    adaptee.jButton4_actionPerformed(e);				  }				}								class MainFrame_jButton6_actionAdapter implements java.awt.event.ActionListener				{				  MainFrame adaptee;								  MainFrame_jButton6_actionAdapter(MainFrame adaptee)				  {				    this.adaptee = adaptee;				  }				  public void actionPerformed(ActionEvent e)				  {				    adaptee.jButton6_actionPerformed(e);				  }				}								class MainFrame_jTextField1_focusAdapter extends java.awt.event.FocusAdapter				{				  MainFrame adaptee;								  MainFrame_jTextField1_focusAdapter(MainFrame adaptee)				  {				    this.adaptee = adaptee;				  }				  public void focusLost(FocusEvent e)				  {				    adaptee.jTextField1_focusLost(e);				  }				}								class MainFrame_jTextField2_focusAdapter extends java.awt.event.FocusAdapter				{				  MainFrame adaptee;								  MainFrame_jTextField2_focusAdapter(MainFrame adaptee)				  {				    this.adaptee = adaptee;				  }				  public void focusLost(FocusEvent e)				  {				    adaptee.jTextField2_focusLost(e);				  }				}			

相关资源