글쓴이 :Jenny 1999년 10월 27일 17:33:16
안녕하세요 !! 지난번 애플릿에서 telnet을 시스템 커맨드로 사용할때 어떻게 해야할지 질문했던적이 있었습니다.
그때 답변해 주신 방법으로 showDocument("telnet://")으로 힌트를 주셔서 시도를 해보았거든요.
저는 솔직히 자바에 초보라인데..현재 SNMP 프로토콜 기반 NMS를 개발하고 있거든요.
사용하는 툴은 SNMP 클래스를 제공해 주는 툴인데..
의도는 이전 에플릿 화면에서 몇가지 입력값을 넘겨 받아 현 화면이 프레임 형태로 실행되고
이 프레임은 메뉴를 구성하고 있지요. 사용자가 텔넷이란 메뉴를 선택하면 showDocument를 사용하여 텔넷이 실행되게끔
하는거입니다. 이때 telnet의 호스트 주소는 이전 화면에서 입력 받은 var_host 값이 와야 하구요.
그런데 자꾸 에러 메세지가 뜨네요. 에러 메세지는 다음 과 같구요..
해당 코드도 함께 첨부합니다.
코드는 길지만 정작 해당되는 코드는 menuListener 클래스 내용에 문제가 있는거 같습니다.
대부분은 툴이 자동적으로 소스를 생성해 주거든요.
바쁘시겠지만 도와 주세요 !!!!! 제 주위에 도움을 청할분이 없어요....흑흑....
제가 워낙 초보라....서....쉬운 문제일거 같은데..잘 모르겠네요...
참고로 코드 부분중 applet.getAppletContext.showDocument("telnet://"+url)을
getAppletContext.showDocument("telnet://"+url) 로 하면 에러 메세지는
"Undefined variable or class name: getAppletContext
getAppletContext.showDocument("telnet://" + url) ;" 이라고 뜹니다.
이전 에플릿 화면에서 입력 값을 변수 var_host와 comm_Str에 주면 지금 프로그램에서는 그 정보를 가지고서
텔넷 명령 수행시 브라우져에 "telnet://var_host 값" 형태로 URL이 넘겨지길 원하는 거거든요.
에러 메세지 :
Attempt to reference method getAppletContext in class java.applet.Applet as an instance variable.
applet.getAppletContext.showDocument("telnet://" + url) ;
==============================================================================
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.* ;
import java.net.* ;
import java.applet.Applet ;
public class menu extends JFrame
{
menuListener Listen = new menuListener() ;
String comm_Str=null;
String var_host = null;
private boolean initialized = false;
java.applet.Applet applet = null;
public menu()
{
this.setSize(375,400);
this.setTitle( " menu" );
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public menu(java.applet.Applet applet)
{
this.setSize(375,400);
this.setTitle( " menu" );
this.applet = applet;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public void init()
{
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {}
if (initialized == true) return;
// Set the layout for the container
getContentPane().setLayout(null);
// let us set the initialzed variable to true so
// we dont initialize again even if init is called
initialized = true;
// Instantiate the beans and add them, if they are visible
//Instantiate JMenuBar1
JMenuBar1= new javax.swing.JMenuBar();
getContentPane().add(JMenuBar1);
JMenuBar1.setBounds(25,20,310,40);
//Instantiate port
port= new com.adventnet.netmonitor.SnmpStatusIcon(applet);
port.setLayout(null);
getContentPane().add(port);
port.setBounds(225,85,45,45);
//Set the Bean properties which have been modified.
setVisible(true) ;
javax.swing.JMenu file = new javax.swing.JMenu("File") ;
file.setMnemonic('F') ;
javax.swing.JMenuItem tel = new javax.swing.JMenuItem("Telnet") ;
tel.addActionListener(Listen) ;
file.add(tel) ;
JMenuBar1.add(file) ;
//Set the modified properties for port
try
{
port.setWriteCommunity("");
port.setCommunity(comm_Str);
port.setTargetHost(var_host);
}catch(Exception ex){};
//Setup the connections between the various Beans
// let us add the init code entered in the screen..
}
public void setVisible(boolean bl)
{
init();
super.setVisible(true);
}
private String getParameter(String input)
{
return "";
}
class menuListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
String command = evt.getActionCommand();
if(command.equals("Telnet")) {
String location=port.getTargetHost() ;
try {
URL url = new URL(location) ;
applet.getAppletContext.showDocument("telnet://" + url) ;
} catch(MalformedURLException e) { e.printStackTrace() ;}
}
}
}
//Declare the beans
javax.swing.JMenuBar JMenuBar1 = null;
com.adventnet.netmonitor.SnmpStatusIcon port = null;
}