Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    22

    Problemi con DrawingPanel

    Ciao a tutti,
    qualcuno puo' dirmi cosa c'é che non va in questo listato visto
    che quando lo compilo con javac mi da il seguente errore .

    DrawingPanel.java:133: 'class' or'interface'expected
    import java.awt.*;

    ecco il listato :

    import java.awt.*;
    public class DrawingPanel extends Panel{
    private static int SHAPE_WIDTH =75;
    private static int SHAPE_HEIGHT =75;
    private static int COLUMN_SPACE_WIDTH =20;
    private static int ROW_SPACE_HEIGHT =120;
    private static Font F1 = new Font("Monospaced",Font.PLAIN,14);
    public static int PANEL_WIDTH = 420;
    public static int PANEL_HEIGHT= 400;

    public DrawingPanel(){
    super();

    }

    public void paint(Graphics g){
    int y;
    g.setColor(Color.red);
    y=20;
    y=drawUnfilledShapes(g,y);
    y +=ROW_SPACE_HEIGHT;
    y=drawFilledShapes(g,y);
    y +=ROW_SPACE_HEIGHT;
    y=drawOtherShapes(g,y);

    }

    private int drawUnfilledShapes(Graphics g,int y){
    int pentagonXs[]=new int [5];
    int pentagonYs[]=new int [5];
    int x=20;


    g.drawArc(x,y, SHAPE_WIDTH,SHAPE_HEIGHT, 0, 90);
    centerText(g,"drawArc",(x + SHAPE_WIDTH/2),Y + SHAPE_HEIGHT,F1);
    x=x + SHAPE_WIDTH +COLUMN_SPACE_WIDTH;

    g.drawOval(x,y,SHAPE_WIDTH,SHAPE_HEIGHT);
    centerText(g,"drawOval",(x+SHAPE_WIDTH/2),y+SHAPE_HEIGHT,F1);
    x=x+SHAPE_WIDTH+COLUMN_SPACE_WIDTH;

    g.drawRect(x,y,SHAPE_WIDTH,SHAPE_HEIGHT);
    centerText(g,"drawRect",(x+SHAPE_WIDTH/2),y+SHAPE_HEIGHT,F1);
    x=x+SHAPE_WIDTH+COLUMN_SPACE_WIDTH;

    g.drawRoundRect(x,y,SHAPE_WIDTH,SHAPE_HEIGHT,15,15 );
    centerText(g,"drawRoundRect",x+SHAPE_WIDTH/2,y+SHAPE_HEIGHT,F1);
    x=x+SHAPE_WIDTH+COLUMN_SPACE_WIDTH;
    return y;

    }

    private int drawFilledShapes(Graphics g, int y){
    int pentagonXs[]=new int[5];
    int pentagonYs[]=new int[5];
    int x=20;

    g.fillArc(x,y , SHAPE_WIDTH, SHAPE_HEIGHT, 0, 90);
    centerText(g,"fillArc",(x+SHAPE_WIDTH/2), y+SHAPE_HEIGHT,F1);
    x=x + SHAPE_WIDTH+COLUMN_SPACE_WIDTH;

    g.fillOval(x,y, SHAPE_WIDTH,SHAPE_HEIGHT);
    centerText(g,"fillOval",(x + SHAPE_WIDTH/2), y + SHAPE_HEIGHT,F1);
    x= x + SHAPE_WIDTH + COLUMN_SPACE_WIDTH;

    g.fillRect(x,y, SHAPE_WIDTH,SHAPE_HEIGHT);
    centerText(g,"fillRect",(x + SHAPE_WIDTH/2), y + SHAPE_HEIGHT,F1);
    x=x + SHAPE_WIDTH + COLUMN_SPACE_WIDTH;

    g.fillRoundRect(x,y, SHAPE_WIDTH,SHAPE_HEIGHT, 15, 15);
    centerText(g,"fillRoundRect",x + SHAPE_WIDTH/2, y + SHAPE_HEIGHT,F1);
    x=x + SHAPE_WIDTH + COLUMN_SPACE_WIDTH;
    return y;

    }

    private int drawOtherShapes(Graphics g, int y){
    int pentagonXs [] =new int [5];
    int pentagonYS[] =new int [5];
    int x= 20;

    g.drawLine(x,y,x + SHAPE_WIDTH, y + SHAPE_HEIGHT);
    centerText(g,"drawLine",(x + SHAPE_WIDTH/2), y +SHAPE_HEIGHT,F1);
    x= x + SHAPE_WIDTH + COLUMN_SPACE_WIDTH;


    calcPentagon(x +SHAPE_WIDHT/2,y + SHAPE_HEIGHT/2, SHAPE_WIDTH/2,
    pentagonXs, pentagonYs);
    g.drawPolyline(pentagonXs,pentagonYs, 5);
    centerText(g,"drawPolyline",(x + SHAPE_WIDTH/2), y+SHAPE_HEIGHT,F1);
    x= x +SHAPE_WIDTH + COLUMN_SPACE_WIDTH;

    Font font = new Font("Verdana", Font.BOLD,10);
    String t = "Questa é una stringa";
    FontMetrics fm=g.getFontMetrics(font);
    int text_width=fm.stringWidth(t);
    g.setFont(font);
    g.drawString(t,x + SHAPE_WIDTH/2 - text_width/2,y+SHAPE_HEIGHT/2);
    centerText(g,"drawString",(x+SHAPE_WIDTH/2),y+SHAPE_HEIGHT,F1);
    return y;

    }

    private int centerText (Graphics g , String t , int x , int y , Font f){
    FontMetrics fm = g.getFontMetrics(font);
    int t_width = fm.stringWidth(t);
    int t_height =fm.getHeight();
    Color color=g.getColor();
    g.setColor(Color.black);
    g.setFont(f);
    g.drawString(t, x - t_width/2, y+ t_height/2+5);
    g.setColor(color);
    return (y+t_height);

    }

    private void calcPentagon(int center_x, int center_y, int radius,
    int[] pointsX, int[] pointsY){
    double delta_radians = 2.0 * Math.PI / 5.0;
    double angle =0.0;

    for( int i =0; i < 5; i++ ) {
    float x=(float) (radius * Math.sin (angle));
    float y=(float) (radius * Math.cos( angle));
    pointsX[i] = Math.round(center_x + x);
    pointsY[i] = Math.round(center_y + y);
    angle +=delta_radians;
    }
    }
    }


    import java.awt.*;
    public class TestDrawingPanel {
    private Frame f;
    private DrawingPanel drawPanel;

    public TestDrawingPanel() {
    f = new Frame ("Disegno di forme con AWT");
    drawPanel =new DrawingPanel();
    }

    public void launchFrame() {
    f.add(drawPanel);
    f.pack();
    f.setSize(new Dimension (DrawingPanel.PANEL_WIDTH,
    DrawingPanel.PANEL_HEIGHT));
    f.setVisible(true);
    }
    public static void main (Sring args[]) {
    TestDrawingPanel gui = new TestDrawingPanel();
    gui.launchFrame();
    }
    }
    Questo mi succede solo da quando ho cominciato a inserire 2 classi nello stesso File, premetto che sono proprio agli inizi e la vedo proprio dura ,comunque grazie a tutti anticipatamente
    Camelon

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,301

    Moderazione

    Hai dimenticato di specificare il linguaggio di programmazione nel titolo della discussione.

    Questo lo modifico io...in futuro stai più attento.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    22

    x alka

    Chiedo scusa x la distrazione ,grazie
    Ciao
    Camelon

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 © 2024 vBulletin Solutions, Inc. All rights reserved.