>
> Cum pot crea o fereastra MODALA care sa fie afisata dintr-un applet?
>
S-a rezolvat!
Solutie:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class test extends Applet implements ActionListener {
Button b;
private Frame findParentFrame(){
Container c = this;
while(c != null){
if (c instanceof Frame)
return (Frame)c;
c = c.getParent();
}
return (Frame)null;
}
public void init(){
setLayout(new FlowLayout());
b = new Button("push me");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e){
Frame f = findParentFrame();
if(f != null){
Dialog d = new Dialog(f, "modalDialog", true);
d.setLayout(new FlowLayout());
d.add(new Label("hello"));
d.pack();
d.setLocation(100,100);
d.show();
}
}
}
>
> Cum pot crea o fereastra MODALA care sa fie afisata dintr-un applet?
>
>
> (Am atasat sursele)=20
>
> applettest.html
>
> <Html>
> <HEAD>
> <TITLE>Bau</Title>
> </HEAD>
> <Body>
> <Center>
> <H2>Apletul AppletTest</H2>
> <APPLET CODE=3D"AppletTest" Width=3D500 Height=3D500>
> </applet>
> </Center>
> </body>
> </html>
> ########################
> AppletTest.java
>
> //package aaa;
>
> import java.awt.*;
> import java.applet.*;
> import java.util.*;
> import java.net.*;
> import java.awt.*;
>
>
>
> public class AppletTest extends Applet {
> Button RunButton1;
>
> private Erroare fereastra;=20
>
> public void init() {
> fereastra =3D new Erroare("");
> add(RunButton1 =3D new Button("Run"));
> resize(400,400);
> }
>
>
> public void paint(Graphics g) {
> RunButton1.resize(80,20);
> RunButton1.move(100,350);
> }
>
> public boolean handleEvent(Event e) {
> int myint;
> if (e.id =3D=3D Event.WINDOW_DESTROY) {
> System.exit(0);
> }
> if (e.id =3D=3D Event.ACTION_EVENT && e.target instanceof Button) {
> if("Run".equals(e.arg)){
> errorMessage("xxxxxxxx");
> return true;
> }
>
> }
> return false;
> }
>
> public void errorMessage(String s){
> Rectangle r =3D getBounds();
> fereastra.setLocation(200,200);
> fereastra.setErrorMessage(s);
> fereastra.show();
> }
>
> }
> ##################
> Erroare.java
>
> import java.awt.*;
> import java.awt.event.*;
>
>
> public class Erroare extends Frame implements ActionListener {
> private String mesaj =3D "Acesta este un mesaj";
> private Label l;
> private Button ok;
> private TextArea text;
> public int width =3D 200, height =3D 120;
> =20
> =20
> Erroare(String mesaj) {
> super("Exemplu");
> ok =3D new Button("ok");
> l=3D new Label(mesaj, Label.CENTER);
> l.setFont(new Font("Helvetica", Font.PLAIN,12));
> setLayout(new BorderLayout());=20
> text =3D new TextArea(mesaj);
> text.setFont( new Font("Monospaced", Font.PLAIN,12));
> add(ok,BorderLayout.SOUTH);
> add(l,BorderLayout.CENTER);
> setSize(width , height);
> setResizable(false);
> setTitle("Atentie..");
> setBackground(new Color(180,180,180));
> =20
> addWindowListener( new WindowAdapter() {
> public void windowClosing(WindowEvent e) {
> // hide();
> dispose();
> }});
>
> ok.addActionListener(this);
> }
>
> public void actionPerformed(ActionEvent e) {
>
> if (e.getSource() instanceof Button) =20
> // hide();
> dispose();
> }
> =20
> public void setErrorMessage(String errMsg) {
> l.setText(errMsg);
> }
>
> =20
> }
>
>
>
>
> -- Binary/unsupported file stripped by Ecartis --
> -- Type: application/octet-stream
> -- File: Erroare.java
>
>
> -- Binary/unsupported file stripped by Ecartis --
> -- Type: application/octet-stream
> -- File: AppletTest.java
>
>
> -- HTML Attachment decoded to text by Ecartis --
> -- File: AppleTest.htm
>
> Bau
>
> Apletul AppletTest
>
>
> ---
> Detalii despre listele noastre de mail: http://www.lug.ro/
>
>
>
---
Detalii despre listele noastre de mail: http://www.lug.ro/