0

別のアプレットから1つのアプレットを呼び出します(別のアプレットを表示するだけです)。最初のアプレットにボタンを配置し、そのactionperformedメソッドでgetcontextapplet()メソッドを使用しました。ただし、2番目のアプレットは表示されませんでした。

最初の反応で2番目のアプレットを表示するにはどうすればよいですか...

コード:

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");
        }

    }
}   
4

2 に答える 2

0

それでも 57 行目に「Illegal Escape Character」エラーが表示される場合は、インスタンス化時に渡す文字列リテラルが原因ですorder

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

Javaエスケープ文字はバックスラッシュ ( \) です。したがって、バック スラッシュを使用するたびに、コンパイラは、バック スラッシュに続く文字をエスケープしようとしていると見なします。たとえば、文字列で

C:\Documents

...コンパイラは、\D2 つの文字ではなく、単一のエスケープ文字として処理しています。表示されているコンパイラ エラーは、その文字列内の一部のエスケープ文字 ( \D\A\t) が認識されないことを示しています。

解決策は、エスケープ文字をエスケープすることです。たとえば、各バックスラッシュの前にブラックスラッシュを付けます。

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

これは、バックスラッシュをエスケープ文字としてではなく、バックスラッシュとして扱うようコンパイラーに指示します。

于 2009-10-19T22:39:24.113 に答える
-1

http://www.wutka.com/hackingjava/ch10.htmまたは単に Google を試して、アプレット間通信を行ってください。

于 2009-10-19T21:16:50.323 に答える