【问题标题】:call another applet in an applet在一个小程序中调用另一个小程序
【发布时间】:2010-12-08 03:37:36
【问题描述】:

我想从另一个小程序调用(只是显示另一个小程序)一个小程序 .我刚刚在我的第一个小程序及其 actionperformed 方法上放置了一个按钮 使用 getcontextapplet() 方法。但是没有显示第二个小程序。

如何在第一个反应时显示第二个小程序...

代码:

import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class home extends Applet implements ActionListener
{
    Container c1;
    Label l1,l2,l3,l4;
    TextField t1;
    Button b1,b2;
    ImageIcon icon;
    Panel p1;
    URL order;

    public void init()
    {
        // Tell the applet not to use a layout manager. 
        setLayout(null); 



        l1=new Label("MINDSOFT CONSULTANTS");
        Font fg=new Font("Times new roman",Font.BOLD,50);
        add(l1);
        l1.setFont(fg);
        l1.setBounds(20,20,800,70);

        l2=new Label("Strength of 5000 employees");
        fg=new Font("Times new roman",Font.BOLD,25);
        l2.setFont(fg);
        l2.setBounds(180,120,500,30);
        add(l2);

        l3=new Label("Specialised in IT and computing services");
        l3.setFont(fg);
        l3.setBounds(90,180,500,30);
        add(l3);

        l4=new Label("A total of 10 different departments");
        l4.setFont(fg);
        l4.setBounds(140,240,500,30);
        add(l4);

        b1=new Button("VIEW DETAIL");
        b1.setBounds(150,320,150,40);
        add(b1);
        b1.addActionListener(this);

        b2=new Button("ADD DETAIL");
        b2.setBounds(450,320,150,40);
        add(b2);

        try
        {
        order =new URL("C:\Documents and Settings\Administrator\Desktop\try\add.html");   
        }
        catch(MalformedURLException e){
        System.out.println("HH");
        }


    }

    public void actionPerformed(ActionEvent e)
    {

        if(e.getSource()==b1)
        {
        getAppletContext().showDocument(order);
        System.out.println("HI");
        }

    }
}   

【问题讨论】:

  • 我建议您需要发布一些代码以避免不可避免地被否决而被遗忘...
  • 你能展示你做了什么以及什么是不受欢迎的行为吗?我不明白。您在一个页面上有两个小程序,您希望一个小程序对另一个小程序执行操作?
  • 其实我需要在第一个小程序中输入一些细节。通过单击按钮,我想获得另一个小程序,我需要在其中添加一些其他信息。
  • 你说:我正在尝试调用其他小程序的另一个小程序按钮单击。我想知道,它是否有效?
  • 很高兴你尝试一下,当你有问题和/或一些代码时回来

标签: java button applet call


【解决方案1】:

如果您仍然在第 57 行看到“非法转义字符”错误,这取决于您在实例化 order 时传递的字符串文字:

order =new URL("C:\Documents and Settings\Administrator\Desktop\try\add.html");   

Java Escape Character 是反斜杠 (\)。因此,每次使用反斜杠时,编译器都会认为您试图转义后面的字符。例如,在字符串中

C:\Documents

...编译器将\D 视为单个转义字符而不是两个字符。您看到的编译器错误告诉您它无法识别该字符串中的某些转义字符(\D\A\t)。

解决方案是转义转义字符,例如在每个反斜杠前加上一个黑斜杠:

order =new URL("C:\\Documents and Settings\\Administrator\Desktop\\try\\add.html"); 

这告诉编译器将反斜杠视为反斜杠,而不是转义字符。

【讨论】:

  • 上述方法已消除错误。但我仍然无法使用 appletviewer 打开另一个小程序。如果可能的话,建议一些其他技术..
【解决方案2】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多