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

📄 sampledesktop13.java

📁 《JBuilder编程技术与实例》(2006 四维科技 人民邮电)赠送代码——图书馆管理系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.text.*;
 import javax.swing.*;
 import javax.swing.event.*;
 import javax.swing.text.*;
 import javax.swing.border.*;
 import javax.swing.colorchooser.*;
 import javax.swing.filechooser.*;
 import javax.accessibility.*;

 import java.awt.*;
 import java.awt.event.*;
 import java.beans.*;
 import java.util.*;
 import java.io.*;
 import java.applet.*;
 import java.net.*;

 import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;

public class SampleDesktop13 extends JFrame  implements ActionListener,ListSelectionListener
{
public JDesktopPane desk;

Properties ht = new Properties();
Properties ht1 = new Properties();
String name,fname,number,add,tele,qua,sums,email;
String  newSelection;
JMenuBar mb;
JMenu menu,menu1,menu2;
JMenuItem sadd,exit,lrecord,about;
JInternalFrame hide=new JInternalFrame();
int document = 1,tabIndex=0;
JTextField[]   nameField;
JList list;
DefaultListModel listModel= new DefaultListModel();
JPanel pix22 = new JPanel();


int wcoboxchange=0;
int count1=0;
JList list1;
DefaultListModel listModel1= new DefaultListModel();
JPanel pix12 = new JPanel();

GregorianCalendar  gcal=new GregorianCalendar();
String idate,doi,dor;
String  rdate;
int id,im,iy,id1,im1,iy1;
int listboxno;

JRadioButton allButton;
JRadioButton javaButton;
JRadioButton cButton;
JRadioButton vbButton;
JLabel stb =new JLabel("The Student Holds This Books..");

int count;
String[] isb;

ArrayList alist=new ArrayList();

String bname,isbn,booktype,author,edition,booksum;

 JPanel p=new JPanel();




public SampleDesktop13(String title){

super(title);
setDefaultCloseOperation(EXIT_ON_CLOSE);

desk = new JDesktopPane();
setContentPane(desk);
 mb = new JMenuBar();
 menu = new JMenu("Student DataBase");
 menu1 = new JMenu("Libary");
 menu2 = new JMenu("Help");
setJMenuBar(menuBar());
mb.add(menu);
mb.add(menu1);
mb.add(menu2);

}

private JMenuBar menuBar(){
 sadd=new JMenuItem(" Student Record");
sadd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
		sadd.addActionListener(this);
menu.add(sadd);
exit=new JMenuItem(" Exit");
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
		exit.addActionListener(this);
                menu.add(exit);

lrecord=new JMenuItem(" Libary Records");
lrecord.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK));
		lrecord.addActionListener(this);
                menu1.add(lrecord);

about=new JMenuItem(" About");
about.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
		about.addActionListener(this);
                menu2.add(about);

                return mb;
}


public void actionPerformed(ActionEvent e){
		if ((e.getSource()==sadd))
			hide=newFile();
                 if ((e.getSource()==lrecord))
			hide=lrecord1();
                 if ((e.getSource()==about))

JOptionPane.showMessageDialog( desk,"Enjoy using this software!");
                 if ((e.getSource()==exit))
			System.exit(0);

                 if ("Cancel".equals(e.getActionCommand())){

                 hide.dispose();}

                 if ("OK".equals(e.getActionCommand())){

                 save();
   JOptionPane.showMessageDialog( hide,"One Record saved");
hide.dispose();


                 }
                 if ("Update".equals(e.getActionCommand())){
 if(wcoboxchange==0){
JOptionPane.showMessageDialog( hide,"Plz select from Combo");
}else{
                 Update();
     JOptionPane.showMessageDialog( hide,"One Record Updated");
                 hide.dispose();
                    wcoboxchange=0;}
                        }
                 if ("Delete".equals(e.getActionCommand())){
if(wcoboxchange==0){
JOptionPane.showMessageDialog( hide,"Plz select from Combo");
}else{
                 Delete();
      JOptionPane.showMessageDialog( hide,"One Record Deleted");
                 hide.dispose();
                wcoboxchange=0;}}
                 if ("Finished".equals(e.getActionCommand())){
       JOptionPane.showMessageDialog( hide,"One Record Showed");

                   hide.dispose();}
   if ("Issue".equals(e.getActionCommand())){
if(nameField[2].getText().length()<1||nameField[1].getText().length()<1)
{
JOptionPane.showMessageDialog( hide,"PLz Give value for All Fields");
if(nameField[2].getText().length()<1){
              nameField[2].requestFocus();}
else{nameField[1].requestFocus();}
}
else{
                Issue();
                  hide.dispose();}
       }
   if ("Return".equals(e.getActionCommand())){
if(nameField[1].getText().length()<1){
JOptionPane.showMessageDialog( hide,"PLz Give value for All Fields");
nameField[1].requestFocus();
}else{
                Returnbook();
                  hide.dispose();}
       }
  if ("Add".equals(e.getActionCommand())){
if(nameField[0].getText().length()<1||nameField[1].getText().length()<1)
{
JOptionPane.showMessageDialog( hide,"PLz Give value for All Fields");
if(nameField[0].getText().length()<1){
              nameField[0].requestFocus();}
else{nameField[1].requestFocus();}
}
else{
                Addbook();
       JOptionPane.showMessageDialog( hide,"One Book Added To Libary");
                  hide.dispose();}}

    if ("Delete Book".equals(e.getActionCommand())){
if(nameField[0].getText().length()<1){
JOptionPane.showMessageDialog( hide,"PLz Give value for All Fields");
nameField[0].requestFocus();
}else{
               Deletebook();
JOptionPane.showMessageDialog( hide,"One Book Deleted From Libary");
                  hide.dispose();}}


if (e.getSource() == allButton){
       //for all books
        nameField[2].setText("");
       changelist("allbooks.txt");


       }
if (e.getSource() == javaButton){
       //for java books
           nameField[2].setText("");
         changelist("javabooks.txt");

       }
if (e.getSource() == cButton){
       //for c books
 nameField[2].setText("");
changelist("cbooks.txt");


       }

if (e.getSource() == vbButton){
       //for vb books
  nameField[2].setText("");
  changelist("vbbooks.txt");
}


}



//list listeners

public void valueChanged(ListSelectionEvent e) {
        if (e.getValueIsAdjusting() == false) {

if (list.getSelectedIndex() == -1) {
}
else{
if(listboxno==0){
String sd=(String)alist.get(list.getSelectedIndex());

nameField[2].setEditable(true);
nameField[2].setText(sd);
 nameField[2].setEditable(false);}
else{

////////////////////////////////////////////

int n=0;
fileopen("issuedbook.txt");


String sums1 = (String) ht.get(newSelection);

String  bdetails1="";

StringTokenizer st = new StringTokenizer(sums1,"#");
				while(st.hasMoreTokens())
				{
                                 n++;
                nameField[n].setEditable(true);

               nameField[n].setText(st.nextToken());
               nameField[n].setEditable(false);


				}

///////////////////////////


nameField[4].setEditable(true);
nameField[4].setText(idate);

nameField[4].setEditable(false);
}
}
}
    }



//list listner upto here


private void changelist(String s){
int n=0;



for( int i=0; i<count; i++ )
   listModel.removeElementAt(0);

count=0; /////////////////////////////////////////////////////////

  alist.clear();
     addtoarray(s);                                           if(!alist.isEmpty()){
for (Iterator iter = alist.iterator(); iter.hasNext();) {
         fileopen("books.txt");


String sums = (String) ht.get((String)(iter.next()));

String  bdetails="";

StringTokenizer st = new StringTokenizer(sums,"#");
				while(st.hasMoreTokens())
				{
		bdetails=bdetails+st.nextToken()+"   ";
				}

        listModel.addElement(bdetails);
        count++;
       }}
else{
listModel.addElement(alist);}
}

//aadd to arraay list

private void addtoarray(String s){
count=0;

try
		{
	DataInputStream	readFile = new DataInputStream(new FileInputStream(s));
	String rec = readFile.readLine();


			while(rec != null)
			{
				StringTokenizer st = new StringTokenizer(rec,"#");
				while(st.hasMoreTokens())
				{

                                         alist.add(st.nextToken());


					rec = readFile.readLine();   //Random Access File
				}
				readFile.close();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}



}

//upto here arraylist




// trying libary Record

private JInternalFrame lrecord1(){
final JInternalFrame f1 = new JInternalFrame ("Test",false,true,false,true);
	int width=Toolkit.getDefaultToolkit().getScreenSize().width;
       	int height=Toolkit.getDefaultToolkit().getScreenSize().height;
       	f1.setBounds( 0, 0, width-10, height - 80 );
       	f1.setTitle("All Fields Relating Books...");
//setDefaultCloseOperation(DISPOSE_ON_CLOSE );

     //alist.clear();
     //addtoarray("allbooks.txt");

final JTabbedPane  fpane =  new JTabbedPane(SwingConstants.TOP);

final JPanel pix1 = new JPanel();
final JPanel pix11 = new JPanel();
//final JPanel pix12 = new JPanel();

final JPanel pix2 = new JPanel();
final JPanel pix21 = new JPanel();
//final JPanel pix22 = new JPanel();
//final JLabel stb =new JLabel("The Student Holds This Books..");

final JPanel pix3 = new JPanel();
final JPanel pix4 = new JPanel();
getContentPane().setLayout(new SpringLayout());
fpane.addTab("Issue ",pix1);
fpane.addTab("Return ",pix2);
fpane.addTab("Add ",pix3);
fpane.addTab("Delete ",pix4);
fpane.setSelectedIndex(0);


final String[] labelStrings = {
            "Name : ",
            "Roll No : ","ISBN No :",
            "DOI : ","DOR :"

        };

final String[] labelStrings1 = {
            "Name : ",
            "ISBN NO : ",
            "DOI : ","ADOR:","DOR :"

        };

final String[] labelStrings2 = {
            "Book Name : ",
            "ISBN NO : ","Book Type :",
            "Author : ","Edition :"

        };


final String[] labelStrings3 = {

            "ISBN NO : "


        };


fpane.getModel().addChangeListener(
 	   new ChangeListener() {
 	      public void stateChanged(ChangeEvent e) {
 		  SingleSelectionModel model = (SingleSelectionModel) e.getSource();
 		  if(model.getSelectedIndex() == fpane.getTabCount()-1) {
                   tabIndex=4;
                   pix4.removeAll();

                  f1.setSize(300,150);

                  pix4.setLayout(new BoxLayout(pix4,BoxLayout.PAGE_AXIS));

pix4.add(createEntryFields(labelStrings3));
pix4.add(createButtons("Delete Book","Cancel"));


 		  }

if(model.getSelectedIndex() == fpane.getTabCount()-2) {

pix3.removeAll();

f1.setSize(300,250);

tabIndex=3;
pix3.setLayout(new BoxLayout(pix3,BoxLayout.PAGE_AXIS));

pix3.add(createEntryFields(labelStrings2));
pix3.add(createButtons("Add","Cancel"));


}
if(model.getSelectedIndex() == fpane.getTabCount()-3) {

pix2.removeAll();
pix21.removeAll();
pix22.removeAll();

pix2.setLayout(new GridLayout());


pix22.setLayout(new GridBagLayout());
GridBagConstraints c1 = new GridBagConstraints();
c1.fill = GridBagConstraints.HORIZONTAL;
c1.weightx = 0.5;
c1.gridx = 0;
c1.gridy = 0;


pix22.add(stb,c1);

c1.ipady = 30;      //make this component tall
c1.weightx = 0.0;
c1.gridwidth = 3;
c1.gridx = 0;
c1.gridy = 1;


stb.setVisible(false);
//listModel.clear();
//alist.clear();
pix22.add(drawlist(),c1);
pix22.setVisible(false);
listboxno=1;



pix21.setLayout(new BoxLayout(pix21,BoxLayout.PAGE_AXIS));
pix21.add(createcombo(1));
pix21.add(createEntryFields(labelStrings1));
pix21.add(createButtons("Return","Cancel"));

pix2.add(pix21);
pix2.add(pix22);
f1.pack();
}
if(model.getSelectedIndex() == fpane.getTabCount()-4) {

tabIndex=1;
  pix1.removeAll();
pix11.removeAll();
pix12.removeAll();

pix1.setLayout(new GridLayout());

 pix11.setLayout(new BoxLayout(pix11,BoxLayout.PAGE_AXIS));
pix11.add(createEntryFields(labelStrings));
pix11.add(createButtons("Issue","Cancel"));

pix12.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;

c.weightx = 0.5;
c.gridx = 0;
c.gridy = 0;


pix12.add(addradiobutton(),c);


c.ipady = 30;      //make this component tall
c.weightx = 0.0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 1;

//listModel.clear();
pix12.add(drawlist(),c);
changelist("allbooks.txt");
listboxno=0;

nameField[3].setText(idate);
  nameField[3].setEditable(false);

returndate();

pix1.add(pix11);
pix1.add(pix12);

⌨️ 快捷键说明

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