Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    aiuto per aggiustare una applet

    Salve a tutti! sono nuovissimo del mondo java e mi arrabatto tra un libro che ho comprato (60€ e molti esempi sono spiegati a "cazzo"..) e esempi e referenze che becco su internet..

    il mio obiettivo finale è quello di scrivere una applet che permetta lo svolgimento di quiz caricati tramite file XML. premetto che vengo dal c++ quindi perdonate evidenti errori grossolani.. questo è il codice che riguarda la parte grafica dell'applet e i miei problemi sono fondamentalmente 2:
    1) perchè il carattere delle TextArea rimane sempre lo stesso, nonostante che alla fine ci sia un ciclo che cambia il carattere a tutti i componenti dell'applet?
    2) l'applet si avvia senza problemi.. salvo che non funge nulla perchè non ho scritto ancora il codice.. perchè però in console mi appaiono un sacco di errori? vorrei correggerli tutti se possibile. grazie.

    ----------------------
    Codice PHP:
    <html>
    <
    head>
    <
    title>cquiz</title>
    </
    head>
    <
    body>
    <
    applet code="gui.class" width="650" height="250">
    <
    param name="file" value="ermellino.xml">
    </
    applet>
    </
    body>
    </
    html
    ----------------------
    Codice PHP:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class 
    gui extends JApplet implements ActionListener {
        
    Font ftFont = new Font("Verdana"Font.PLAIN10);
        
    JLabel lblTitle;
        
    JComboBox cbList;
        
    JButton bReset;
        
    JTextField txtAnswer;
        
    JButton bSend;
        
    JTextArea txtDescription;
        
    JScrollPane sp_txtDescription;
        
    JTextArea txtQuestion;
        
    JScrollPane sp_txtQuestion;
        
    JLabel lblQuestion;
        
    JButton bNext;
        
    JButton bBack;
        
    JButton bHint;
        
    JComboBox cbGradeList;
        
    JButton bCheck;
        
    JTextArea txtReport;
        
    JScrollPane sp_txtReport;
        
    JLabel lblFile;
        
    JLabel lblLevel;
        
    JButton bRestart;
        
    boolean secureMode=true;

        public 
    void init() {
            
            
    String parametro getParameter("file");  
                 
            
    guiLayout customLayout = new guiLayout();

            
    setFont(ftFont);
            
    setLayout(customLayout);

            
    lblTitle = new JLabel("Title:");
            
    add(lblTitle);

            
    cbList = new JComboBox();
            
    cbList.addItem("item1");
            
    cbList.addItem("item2");
            
    cbList.addActionListener(this);
            
    add(cbList);

            
    bReset = new JButton("Reset");
            
    bReset.addActionListener(this);
            
    add(bReset);

            
    txtAnswer = new JTextField("");
            
    add(txtAnswer);

            
    bSend = new JButton("Send");
            
    bSend.addActionListener(this);
            
    add(bSend);

            
    txtDescription = new JTextArea("description");
            
    sp_txtDescription = new JScrollPane(txtDescription);
            
    add(sp_txtDescription);

            
    txtQuestion = new JTextArea("");
            
    sp_txtQuestion = new JScrollPane(txtQuestion);
            
    add(sp_txtQuestion);

            
    lblQuestion = new JLabel("Question");
            
    add(lblQuestion);

            
    bNext = new JButton("Next >>");
            
    bNext.addActionListener(this);
            
    add(bNext);

            
    bBack = new JButton("<< Back");
            
    bBack.addActionListener(this);
            
    add(bBack);

            
    bHint = new JButton("Hint");
            
    bHint.addActionListener(this);
            
    add(bHint);

            
    cbGradeList = new JComboBox();
            
    cbGradeList.addItem("item1");
            
    cbGradeList.addItem("item2");
            
    cbGradeList.addActionListener(this);
            
    add(cbGradeList);

            
    bCheck = new JButton("Check Answers");
            
    bCheck.addActionListener(this);
            
    add(bCheck);

            
    txtReport = new JTextArea("report");
            
    sp_txtReport = new JScrollPane(txtReport);
            
    txtReport.setEnabled(true);
            
    add(sp_txtReport);

            
    lblFile = new JLabel("File:");
            
    add(lblFile);

            
    lblLevel = new JLabel("Level:");
            
    add(lblLevel);
            
            
    bRestart = new JButton("Re-Start");
            
    bRestart.addActionListener(this);
            
    add(bRestart);

            
    setSize(getPreferredSize());
            
        }

        public 
    void actionPerformed(ActionEvent e)
            { 
                if (
    e.getSource()==bSend)
                {   
                    
    boolean ok=true;
                    if (
    secureMode)
                    {
                       
    MsgBox message = new MsgBox(new JFrame("") , "Alert""Confirm?"true);
                       
    requestFocus();
                       if (!
    message.id)  ok=false;                
                       
    message.dispose();       
                    }
                    if (
    ok)
                    {
    /*next question*/}
                }
            }   
            
        
    /**
         * Called by the browser or applet viewer to inform this JApplet that it 
         * should start its execution. It is called after the init method and 
         * each time the JApplet is revisited in a Web page. 
         */
        
    public void start()
        {
            
    // provide any code requred to run each time 
            // web page is visited
        
    }

        
    /** 
         * Called by the browser or applet viewer to inform this JApplet that
         * it should stop its execution. It is called when the Web page that
         * contains this JApplet has been replaced by another page, and also
         * just before the JApplet is to be destroyed. 
         */
        
    public void stop()
        {
            
    // provide any code that needs to be run when page
            // is replaced by another page or before JApplet is destroyed 
        
    }      
    }


    class 
    guiLayout implements LayoutManager {

        public 
    guiLayout() {
        }

        public 
    void addLayoutComponent(String nameComponent comp) {
        }

        public 
    void removeLayoutComponent(Component comp) {
        }

        public 
    Dimension preferredLayoutSize(Container parent) {
            
    Dimension dim = new Dimension(00);

            
    Insets insets parent.getInsets();
            
    dim.width 615 insets.left insets.right;
            
    dim.height 256 insets.top insets.bottom;

            return 
    dim;
        }

        public 
    Dimension minimumLayoutSize(Container parent) {
            
    Dimension dim = new Dimension(00);
            return 
    dim;
        }

        public 
    void layoutContainer(Container parent) {
            
            
    Font ftFont = new Font("Verdana"Font.PLAIN10);
            
    Insets insets parent.getInsets();

            
    Component c;
            
    parent.getComponent(0);
            if (
    c.isVisible()) {c.setBounds(insets.left+280,insets.top+16,328,24);}
            
    parent.getComponent(1);
            if (
    c.isVisible()) {c.setBounds(insets.left+96,insets.top+16,160,24);}
            
    parent.getComponent(2);
            if (
    c.isVisible()) {c.setBounds(insets.left+280,insets.top+224,104,24);}
            
    parent.getComponent(3);
            if (
    c.isVisible()) {c.setBounds(insets.left+376,insets.top+200,144,24);}
            
    parent.getComponent(4);
            if (
    c.isVisible()) {c.setBounds(insets.left+512,insets.top+224,96,24);}
            
    parent.getComponent(5);
            if (
    c.isVisible()) {c.setBounds(insets.left+280,insets.top+40,328,40);}
            
    parent.getComponent(6);
            if (
    c.isVisible()) {c.setBounds(insets.left+280,insets.top+104,328,96);}
            
    parent.getComponent(7);
            if (
    c.isVisible()) {c.setBounds(insets.left+280,insets.top+80,328,24);}
            
    parent.getComponent(8);
            if (
    c.isVisible()) {c.setBounds(insets.left+528,insets.top+200,80,24);}
            
    parent.getComponent(9);
            if (
    c.isVisible()) {c.setBounds(insets.left+280,insets.top+200,88,24);}
            
    parent.getComponent(10);
            if (
    c.isVisible()) {c.setBounds(insets.left+392,insets.top+224,112,24);}
            
    parent.getComponent(11);
            if (
    c.isVisible()) {c.setBounds(insets.left+96,insets.top+40,160,24);}
            
    parent.getComponent(12);
            if (
    c.isVisible()) {c.setBounds(insets.left+136,insets.top+72,120,24);}
            
    parent.getComponent(13);
            if (
    c.isVisible()) {c.setBounds(insets.left+16,insets.top+96,240,152);}
            
    parent.getComponent(14);
            if (
    c.isVisible()) {c.setBounds(insets.left+16,insets.top+16,120,24);}
            
    parent.getComponent(15);
            if (
    c.isVisible()) {c.setBounds(insets.left+16,insets.top+40,120,24);}
            
    parent.getComponent(16);
            if (
    c.isVisible()) {c.setBounds(insets.left+16,insets.top+72,112,24);}
            
            for (
    int i=0i<=16i++)
             
    parent.getComponent(i).setFont(ftFont);
        }


  2. #2
    ecco, posto anche gli errori così non vi dovete sbattere a compilare l'applet!

    -----
    Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException:
    No such child: 1
    at java.awt.Container.getComponent(Container.java:280 )
    at guiLayout.layoutContainer(gui.java:186)
    at java.awt.Container.layout(Container.java:1401)
    at java.awt.Container.doLayout(Container.java:1390)
    at java.awt.Container.validateTree(Container.java:147 3)
    at java.awt.Container.validateTree(Container.java:148 0)
    at java.awt.Container.validateTree(Container.java:148 0)
    at java.awt.Container.validateTree(Container.java:148 0)
    at java.awt.Container.validateTree(Container.java:148 0)
    at java.awt.Container.validateTree(Container.java:148 0)
    at java.awt.Container.validate(Container.java:1448)
    at sun.applet.AppletViewer$1AppletEventListener.apple tStateChanged(Apple
    tViewer.java:216)
    at sun.applet.AppletPanel.dispatchAppletEvent(AppletP anel.java:246)
    at sun.applet.AppletPanel$7.run(AppletPanel.java:844)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 461)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchTh
    read.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThre
    ad.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)

    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)

    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)

  3. #3
    update: gli errori appaiono solo se nel codice html della pagina che fa partire l'applet è presente il parametro "file"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.