📄 sampledesktop13.java
字号:
f1.pack();
}
}
}
);
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;
id= gcal.get(Calendar.DATE);
im=(int)gcal.get(Calendar.MONTH)+1;
iy=gcal.get(Calendar.YEAR);
idate=id+"/"+im+"/"+iy;
nameField[3].setText(idate);
nameField[3].setEditable(false);
returndate();
pix1.add(pix11);
pix1.add(pix12);
f1.pack();
f1.getContentPane().add(fpane);
JDesktopPane desktop = new JDesktopPane();
desktop.add(f1);
desk.add(f1);
f1.setVisible(true);
//f1.pack();
return f1;
}
//libary record upto here
//Issueing a book
private void Issue(){
String isbn1=nameField[2].getText();
fileopen("srecord.txt");
try{
number=nameField[1].getText();
String ert=(String)ht.get(number);
ht.clear();
insertroll(number,"irollno.txt");
if(ert.length()>1){
doi=nameField[3].getText();
dor=nameField[4].getText();
String tmp=isbn1+"#"+doi+"#"+dor;
ht1.clear();
fileopen1("issuedbook.txt");
ht1.put(number,tmp);
writetofile1("issuedbook.txt");
JOptionPane.showMessageDialog( hide,"One Book Issued");
}
}catch(NullPointerException e){
JOptionPane.showMessageDialog( hide,"Sorry u R Not A Student");}
}
protected void writetofile1(String s){
try{
File f=new File(s);
f.delete();
FileOutputStream fout = new FileOutputStream(s,true) ;
ht1.store(fout,"Prosun's creation");
fout.close();
}catch(IOException e){}
}
//book issue upto here
//return a book
private void Returnbook(){
comparedate();
fileopen("issuedbook.txt");
deletearecord("issuedbook.txt",newSelection);
deletefromsuppotedfile("irollno.txt",newSelection);
JOptionPane.showMessageDialog( hide,"One Book Returned");
ht.clear();
}
//function for deleting a record from file
private void deletearecord(String fn,String key){
File f=new File(fn);
f.delete();
try{
FileOutputStream fout = new FileOutputStream(fn,true);
ht.remove(key);
ht.store(fout,"Prosun's creation");
fout.close();
}catch(IOException e){}
ht.clear();
}
//function for deleting a record from file upto here
//book return upto here
//delete book from libary
private void Deletebook(){
String sd=nameField[0].getText();
fileopen("books.txt");
deletearecord("books.txt",sd);
deletefromsuppotedfile("cbooks.txt",sd);
deletefromsuppotedfile("javabooks.txt",sd);
deletefromsuppotedfile("vbbooks.txt",sd);
deletefromsuppotedfile("allbooks.txt",sd);
}
//delete book from libary upto here
/////////////////Delete Book no from Supporting files////////////////
private void deletefromsuppotedfile(String fn,String key){
try
{
DataInputStream readFile = new DataInputStream(new FileInputStream(fn));
String rec = readFile.readLine();
String rolllist=null;
DataOutputStream writeFile1 = new DataOutputStream(new FileOutputStream("temp1.txt",true));
while(rec != null)
{
StringTokenizer st = new StringTokenizer(rec,"#");
while(st.hasMoreTokens())
{
String n=st.nextToken();
rec = readFile.readLine();
if(!n.equals(key)){
//writimg to a tempfile
writeFile1.writeBytes(n+"#");
}
}
readFile.close();
writeFile1.close();
}
filecopy("temp1.txt",fn);
}
catch(Exception e)
{
e.printStackTrace();
}
}
////////////////////////upto here///////////////////////////////////////
private void comparedate(){
String sr=nameField[3].getText();
int rd,rm,ry;
StringTokenizer st = new StringTokenizer(sr,"/");
rd=Integer.parseInt(st.nextToken());
rm=Integer.parseInt(st.nextToken());
ry=Integer.parseInt(st.nextToken());
if(iy>ry){
JOptionPane.showMessageDialog( hide,"You Must Give Fine For Delay");
}else{
if(im>rm){
JOptionPane.showMessageDialog( hide,"You Must Give Fine For Delay");}
else{
if(id>rd)
JOptionPane.showMessageDialog( hide,"You Must Give Fine For Delay");}
}
}
private void returndate(){
im1=im;
iy1=iy;
id1=id+15;
if(im1==1||im1==3||im1==5||im1==7||im1==8||im1==10||im1==12){
if(id1>31){
im1=im1+1;
id1=id1-31;
if(im1>12){
im1=im1-12;
iy1=iy1+1;
}}}
if(im1==4||im1==6||im1==9||im1==11){
if(id1>30){
im1=im1+1;
id1=id1-30;
if(im1>12){
im1=im1-12;
iy1=iy1+1;}
}}
if(im1==2){
if(id1>28){
im1=im1+1;
id1=id1-28;
if(im1>12){
im1=im1-12;
iy1=iy1+1;
}}}
rdate = id1+"/"+im1+"/"+iy1;
nameField[4].setEditable(true);
nameField[4].setText(rdate);
nameField[4].setEditable(false);
}
private JPanel addradiobutton(){
JPanel pix12= new JPanel();
String allString= "All";
String javaString= "Java";
String cString= "C";
String vbString= "Vb";
allButton = (JRadioButton) pix12.add(new JRadioButton(allString));
allButton.setActionCommand(allString);
allButton.setSelected(true);
javaButton =(JRadioButton) pix12.add( new JRadioButton(javaString));
javaButton.setActionCommand(javaString);
cButton =(JRadioButton) pix12.add( new JRadioButton(cString));
cButton.setActionCommand(cString);
vbButton =(JRadioButton) pix12.add( new JRadioButton(vbString));
vbButton.setActionCommand(vbString);
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(allButton);
group.add(javaButton);
group.add(cButton);
group.add(vbButton);
//Register a listener for the radio buttons.
allButton.addActionListener(this);
javaButton.addActionListener(this);
cButton.addActionListener(this);
vbButton.addActionListener(this);
return pix12;
}
private JPanel drawlist() {
listModel.addElement("prosun");
count++;
//Create the list and put it in a scroll pane.
list = new JList(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedIndex(0);
list.addListSelectionListener(this);
list.setVisibleRowCount(5);
JScrollPane listScrollPane = new JScrollPane(list);
String name = listModel.getElementAt(
list.getSelectedIndex()).toString();
//Create a panel that uses BoxLayout.
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane,
BoxLayout.LINE_AXIS));
buttonPane.add(Box.createHorizontalStrut(5));
//buttonPane.add(new JSeparator(SwingConstants.HORIZONTAL));
buttonPane.add(Box.createHorizontalStrut(5));
buttonPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
buttonPane.add(listScrollPane, BorderLayout.CENTER);
return buttonPane;
}
private void Addbook(){
fileopen("books.txt");
bname=nameField[0].getText();
isbn=nameField[1].getText();
booktype=nameField[2].getText();
author=nameField[3].getText();
edition=nameField[4].getText();
booksum=bname+"#"+author+"#"+edition;
ht.put(isbn,booksum);
writetofile("books.txt");
try{
DataOutputStream writeFile2 = new DataOutputStream(new FileOutputStream("allbooks.txt",true)); writeFile2.writeBytes(isbn+"#");
writeFile2.close();
}catch(IOException e){}
if(booktype.equals("c")){
try{
DataOutputStream writeFile1 = new DataOutputStream(new FileOutputStream("cbooks.txt",true)); writeFile1.writeBytes(isbn+"#");
writeFile1.close();
}catch(IOException e){}
}
if(booktype.equals("vb")){
try{
DataOutputStream writeFile1 = new DataOutputStream(new FileOutputStream("vbbooks.txt",true)); writeFile1.writeBytes(isbn+"#");
writeFile1.close();
}catch(IOException e){}
}
if(booktype.equals("java")){
try{
DataOutputStream writeFile1 = new DataOutputStream(new FileOutputStream("javabooks.txt",true)); writeFile1.writeBytes(isbn+"#");
writeFile1.close();
}catch(IOException e){}
}
}
private JInternalFrame newFile(){
final JInternalFrame f = new JInternalFrame ("Test",false,true,false,true);
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
f.setBounds( 0, 0, width-10, height - 80 );
f.setTitle("All Fields Regarding Students..");
final JTabbedPane fpane = new JTabbedPane(SwingConstants.TOP);
final JPanel pix1 = new JPanel();
final JPanel pix2 = new JPanel();
final JPanel pix3 = new JPanel();
final JPanel pix4 = new JPanel();
getContentPane().setLayout(new SpringLayout());
fpane.addTab("Add",pix1);
fpane.addTab("Update",pix2);
fpane.addTab("Search",pix3);
fpane.addTab("Delete",pix4);
fpane.setSelectedIndex(0);
final String[] labelStrings = {
"Name : ",
"Father Name: ","Roll No :",
"Address: ","Qualification :",
"E_Mail: ","Tele Ph :"
};
final String[] labelStrings1 = {
"Name : ",
"Father Name: ",
"Address: ","Qualification :",
"E_Mail: ","Tele Ph :"
};
fpane.getModel().addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent e) {
SingleSelectionModel model = (SingleSelectionModel) e.getSource();
if(model.getSelectedIndex() == fpane.getTabCount()-1) {
tabIndex=4;
wcoboxchange=0;
pix4.removeAll();
pix4.setLayout(new BoxLayout(pix4,BoxLayout.PAGE_AXIS));
pix4.add(createcombo(0));
pix4.add(createEntryFields(labelStrings1));
pix4.add(createButtons("Delete","Cancel"));
}
if(model.getSelectedIndex() == fpane.getTabCount()-2) {
pix3.removeAll();
wcoboxchange=0;
pix3.setLayout(new BoxLayout(pix3,BoxLayout.PAGE_AXIS));
pix3.add(createcombo(0));
pix3.add(createEntryFields(labelStrings1));
pix3.add(createButtons("Finished","Cancel"));
tabIndex=3;
}
if(model.getSelectedIndex() == fpane.getTabCount()-3) {
wcoboxchange=0;
pix2.removeAll();
pix2.setLayout(new BoxLayout(pix2,BoxLayout.PAGE_AXIS));
pix2.add(createcombo(0));
pix2.add(createEntryFields(labelStrings1));
pix2.add(createButtons("Update","Cancel"));
tabIndex=2;
}
if(model.getSelectedIndex() == fpane.getTabCount()-4) {
wcoboxchange=0;
tabIndex=1;
pix1.removeAll();
pix1.setLayout(new BoxLayout(pix1,BoxLayout.PAGE_AXIS));
pix1.add(createEntryFields(labelStrings));
pix1.add(createButtons("OK","Cancel"));
}
}
}
);
pix1.setLayout(new BoxLayout(pix1,BoxLayout.PAGE_AXIS));
pix1.add(createEntryFields(labelStrings));
pix1.add(createButtons("OK","Cancel"));
f.getContentPane().add(fpane);
JDesktopPane desktop = new JDesktopPane();
desktop.add(f);
desk.add(f);
f.setLocation(100,75);
f.setVisible(true);
return f;
}
//trying from downloded code
public JFormattedTextField getTextField(JSpinner spinner) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -