SaveFileDialog.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:3k
- /* $Id: SaveFileDialog.java,v 1.3 2002/09/09 05:46:50 parasuraman Exp $ */
- /*
- * @(#)SaveFileDialog.java
- * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import java.applet.*;
- import java.io.*;
- import java.awt.*;
- import java.util.*;
- import com.adventnet.snmp.snmp2.SASClient;
- public class SaveFileDialog extends Applet {
-
-
- public SASClient sframe;
- Font fontb = new Font("Helvetica", Font.BOLD, 16);
- Font font = new Font("Helvetica", Font.PLAIN, 16);
- String advent = new String("AdventNet Save File Dialog");
- TextField field;
- TextArea text;
-
- /* This takes care of the look of SaveFileDialog */
-
- public void init() {
-
- try{
- sframe = new SASClient(this,true,2);}
- catch(Exception e){}
- //sframe.protocol = 2;
- setBackground(Color.lightGray);
- GridBagLayout gridbag = new GridBagLayout(); // we'll use gridbag
- GridBagConstraints c = new GridBagConstraints();
- setLayout(gridbag);
- c.fill = GridBagConstraints.BOTH;
- c.weightx = 1.0;
- c.insets = new Insets(20,10,0,10);
-
- c.gridwidth = GridBagConstraints.REMAINDER;
- Label label = new Label("Enter the Text to be Saved");label.setFont(fontb);
- gridbag.setConstraints(label,c);
- add(label);
- c.insets = new Insets(0,10,10,10);
- c.gridwidth = GridBagConstraints.REMAINDER;
- text = new TextArea();
- text.setEditable(true);
- gridbag.setConstraints(text,c);
- add(text);
- c.gridwidth = 1;
- label = new Label("Enter File Name to be saved");label.setFont(fontb);
- gridbag.setConstraints(label,c);
- add(label);
- c.gridwidth = GridBagConstraints.REMAINDER;
- field = new TextField();
- field.setEditable(true);
- gridbag.setConstraints(field,c);
- add(field);
- // Bottom panel is a panel sub-class we've defined for a row of buttons
- c.weighty = 0.0;
- c.gridheight = 1;
- String buttons[] = {"Save Text", "Cancel"};
- ButtonPanel bp = new ButtonPanel(buttons);
- bp.setFont(fontb);
- gridbag.setConstraints(bp,c);
- add(bp);
- resize(550,400);
- // setBackground(Title.fadedBlue);
- }
- /* for OK and CANCEL actions */
- public boolean action(Event e, Object arg) {
- if (e.target instanceof Button) {
- //if (arg.equals("Cancel")) this.hide();
- //else
- if (arg.equals("Save Text")) {
-
-
- try{
-
- String filename = (new File(field.getText())).getName(); // get rid of path
-
- //File f = new File("HTTPUsers"+File.separator+filename);
-
- //sframe.saveFile(f.getAbsolutePath(),(text.getText()).getBytes());
- sframe.saveFile(filename,(text.getText()).getBytes());
-
- }
-
- catch(Exception exc1){}
-
- //this.destroy();
- }
-
- }
- return true;
- }
- /** Allow another MIB load only if shown again */
- public synchronized void show() {
- super.show();
- }
- /** To handle destroy window - pass all else to parent */
- public boolean handleEvent(Event e) {
- if (e.id == Event.WINDOW_DESTROY) {
- hide();
- }
- return super.handleEvent(e);
- }
- }