⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 application.java

📁 这是一个有关网上音像店的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.math.*;
import java.io.*;
import java.util.*;
import javax.swing.text.*;
import java.util.Date;
import java.text.*;

class ApplicationFrame extends JFrame implements ActionListener{
   private JLayeredPane desktop;
   public ApplicationFrame(){
      Container ContentPane=getContentPane();
      desktop=new JDesktopPane();
      desktop.setOpaque(false);
      ContentPane.add(desktop ,BorderLayout.CENTER);
      
      /**设置菜单*/
      JMenuBar mbar=new JMenuBar();
      this.setJMenuBar(mbar);
      
      JMenu appMenu=new JMenu("操作");
      JMenuItem exitButton=new JMenuItem("退出");
      exitButton.addActionListener(this);
      appMenu.add(exitButton);
      mbar.add(appMenu);
      
      JMenu FileMenu=new JMenu("会员专区");
      JMenuItem commButton=new JMenuItem("会员信息");
      commButton.addActionListener(this);
      FileMenu.add(commButton);
      mbar.add(FileMenu);
      
      JMenu MediaMenu=new JMenu("音像店");
      JMenuItem cdButton=new JMenuItem("CD");
      cdButton.addActionListener(this);
      MediaMenu.add(cdButton);
      mbar.add(MediaMenu);
      
      setSize(600,500);
      setTitle("李玉荣的音像店");
      
      /**注册无名内部类,处理窗口关闭事件*/
       addWindowListener(new WindowAdapter()
      { public void windowClosing(WindowEvent e){
               System.exit(0);
        }
      });
   }
   
   public void actionPerformed(ActionEvent evt){
      String s=evt.getActionCommand();
      if(s.equals("退出"))
      {  System.exit(0); }
      
   if(s.equals("会员信息")){
   /**新建CommunicationInternalFrame对象comm*/
   CommunicationInternalFrame comm=new CommunicationInternalFrame("会员");
   /**将comm添加到主窗口*/
   desktop.add(comm,JLayeredPane.DEFAULT_LAYER);
   comm.setVisible(true);
   }
   
   if(s.equals("CD")){
   /**新建CDInternalFrame对象cd*/
   CDInternalFrame cd=new CDInternalFrame();
   /**将cd添加到主窗口*/
   desktop.add(cd,JLayeredPane.DEFAULT_LAYER);
   cd.setVisible(true);
   }
  }
}
     
   public class Application{
      public static void main(String args[]){
        JFrame jf=new ApplicationFrame();
        jf.setVisible(true);
      }
   }  
   
   
class CDInternalFrame extends JInternalFrame implements ActionListener{
    private JTextField JTFname;//CD名称文本区
    private JTextField JTFprice;//CD价格文本区
    private JTextField JTFpress;//CD出版社文本区
    private JTextField JTFartist;//CD演唱者文本区
    private JTextField JTFpublisher;//CD发行商文本区
    private JTextField JTFisrc;//CD ISRC文本区

    private JList JListCD;     //CD信息列表
    private static final int MAX_ARRAY=200;
    MyCD CDInfo[];  //MyCD对象数组
    int CDCount;    //数组中对象的个数

CDInternalFrame(){
    JTFname=new JTextField(20);
    JTFprice=new JTextField(20);
    JTFpress=new JTextField(20);
    JTFartist=new JTextField(20);
    JTFpublisher=new JTextField(20);
    JTFisrc=new JTextField(20);

    JListCD=new JList();
    JListCD.setVisibleRowCount(6);
    JListCD.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane listpane=new JScrollPane(JListCD);

    JPanel cdpane=new JPanel();
    cdpane.setLayout(new GridLayout(6,2));
    cdpane.add(new JLabel("CD的名称:",JLabel.RIGHT));
    cdpane.add(JTFname);
    cdpane.add(new JLabel("CD的价格:",JLabel.RIGHT));
    cdpane.add(JTFprice);
    cdpane.add(new JLabel("CD的出版社:",JLabel.RIGHT));
    cdpane.add(JTFpress);
    cdpane.add(new JLabel("CD的演唱者:",JLabel.RIGHT));
    cdpane.add(JTFartist);
    cdpane.add(new JLabel("CD的发行商:",JLabel.RIGHT));
    cdpane.add(JTFpublisher);
    cdpane.add(new JLabel("CD的ISRC:",JLabel.RIGHT));
    cdpane.add(JTFisrc);

    Container contentPane=getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(listpane,BorderLayout.CENTER);
    contentPane.add(cdpane,BorderLayout.SOUTH);
 
    JMenuBar mbar=new JMenuBar();
    JMenu opeMenu=new JMenu("操作");
    JMenuItem addItem =new JMenuItem("增加");
    addItem.addActionListener(this);
    JMenuItem altItem =new JMenuItem("修改");
    altItem.addActionListener(this);
    JMenuItem delItem =new JMenuItem("删除");
    delItem.addActionListener(this);
    opeMenu.add(addItem);
    opeMenu.add(altItem);
    opeMenu.add(delItem);
    mbar.add(opeMenu);
    this.setJMenuBar(mbar);

    setTitle("CD销售 作者:李玉荣");
    setSize(500,400);
    setResizable(true);
    setClosable(true);
    setMaximizable(true);
    setIconifiable(true);

    CDInfo=new MyCD[MAX_ARRAY];
    CDCount=0;
    for(int i=0;i<MAX_ARRAY;i++)
    CDInfo[i]=null;
}

public void actionPerformed(ActionEvent evt){
     String s=evt.getActionCommand();
     if(s.equals("增加")){
         if(CDCount==MAX_ARRAY){
         JOptionPane.showMessageDialog(this,"列表已经达到最大,无法添加新内容     !","提示",JOptionPane.INFORMATION_MESSAGE);
         return;
     }

     MyCD cdtemp=new MyCD("",0,"","","","");
     cdtemp.setName(JTFname.getText());
     try{
        cdtemp.setPrice(Float.parseFloat(JTFprice.getText()));
     }
     catch(NumberFormatException e){
         JOptionPane.showMessageDialog(this,"价格输入格式错误!","错误     ",JOptionPane.INFORMATION_MESSAGE);
     return;
     }
     cdtemp.setPress(JTFpress.getText());
     cdtemp.setArtist(JTFartist.getText());
     cdtemp.setCDPublisher(JTFpublisher.getText());
     cdtemp.setCDISRC(JTFisrc.getText());

     CDInfo[CDCount]=cdtemp;
     CDCount++;

     String list[]=new String[CDCount];
     for(int j=0;j<CDCount;j++){
         list[j]="名称:"+CDInfo[j].getName()
                +"  价格: "+CDInfo[j].getPrice()
                +"  出版社: "+CDInfo[j].getPress()
                +"  演唱者: "+CDInfo[j].getArtist()
                +"  发行商: "+CDInfo[j].getCDPublisher()
                +"  ISRC:"+CDInfo[j].getCDISRC();
     }
     JListCD.setListData(list);
     }

     if(s.equals("修改")){
        MyCD cdtemp=new MyCD("",0,"","","","");
        cdtemp.setName(JTFname.getText());
        try{
           cdtemp.setPrice(Float.parseFloat(JTFprice.getText()));
        }
        catch(NumberFormatException e){
           JOptionPane.showMessageDialog(this,"价格输入格式错误!","错误          ",JOptionPane.INFORMATION_MESSAGE);
     }
     cdtemp.setPress(JTFpress.getText());
     cdtemp.setArtist(JTFartist.getText());
     cdtemp.setCDPublisher(JTFpublisher.getText());     
     cdtemp.setCDISRC(JTFisrc.getText());
     CDInfo[JListCD.getSelectedIndex()]=cdtemp;

     String list[]=new String[CDCount];
     for(int j=0;j<CDCount;j++){
         list[j]="名称:"+CDInfo[j].getName()
                +"  价格: "+CDInfo[j].getPrice()
                +"  出版社: "+CDInfo[j].getPress()
                +"  演唱者: "+CDInfo[j].getArtist()
                +"  发行商: "+CDInfo[j].getCDPublisher()
                +"  ISRC:"+CDInfo[j].getCDISRC();
     }
     JListCD.setListData(list);
   }
   if(s.equals("删除")){
       for(int i=JListCD.getSelectedIndex();i<CDCount-1;i++){
          CDInfo[i]=CDInfo[i+1];
       }
       CDCount--;
       String list[]=new String[CDCount];
       for(int j=0;j<CDCount;j++){
           list[j]="名称:"+CDInfo[j].getName()
                +"  价格: "+CDInfo[j].getPrice()
                +"  出版社: "+CDInfo[j].getPress()
                +"  演唱者: "+CDInfo[j].getArtist()
                +"  发行商: "+CDInfo[j].getCDPublisher()
                +"  ISRC:"+CDInfo[j].getCDISRC();
     }
     JListCD.setListData(list);
     }
   }
}


class CommunicationInternalFrame extends JInternalFrame {
	/**定义各标签,包括姓名、邮政编码、通信地址、电话、手机、email*/
   JLabel name;
   JLabel zip;
   JLabel address;
   JLabel telephone;
   JLabel mobile;
   JLabel email;
   /**定义文本框,包括姓名、邮政编码、通信地址、电话、手机、email文本框*/
   JTextField nametext;
   JTextField ziptext;
   JTextField addtext;
   JTextField teltext;
   JTextField mobtext;
   JTextField emailtext;
  
   /**设置"添加""查找""清空""退出"按钮*/
   JButton add;
   JButton find;
   JButton clear;
   
   ArrayList al;
   CommunicationInternalFrame(String s){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -