Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

HITNO potrebna main class

[es] :: Java :: HITNO potrebna main class
(Zaključana tema (lock), by hyle)

[ Pregleda: 1771 | Odgovora: 7 ] > FB > Twit

Postavi temu

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

anon81718

Član broj: 81718
Poruke: 24
92.241.158.*



Profil

icon HITNO potrebna main class09.12.2008. u 13:33 - pre 187 meseci
Poshtovanje!
Potrebna mi je pomoc u kreiranju main class za code (dole)...trebalo bi da se otvara u appletu 500x500.
Znam da nije problem!
Hvala!

Code:
import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    
    
    public class SimplePolygons extends Applet implements MouseListener {
            
            
       /* Variables for implementing polygon input. */
       
       private int[] xCoord, yCoord;  // Arrays containing the points of 
                                      //   the polygon.  Up to 500 points 
                                      //   are allowed.
                                      
       private int pointCt;  // The number of points that have been input.
       
       private final static Color polygonColor = Color.red;  
                            // Color that is used to draw the polygons.  
    
       public void init() {
             // Initialize the applet.  The applet listens for mouse events.
             // Arrays are created to hold the points.
          setBackground(Color.white);
          addMouseListener(this);
          xCoord = new int[500];
          yCoord = new int[500];
          pointCt = 0;
       }
       
       
       public void paint(Graphics g) {
       
             // The paint() routine does nothing but draw a 1-pixel black 
             // border around the applet.  Polygons drawn on the applet
             // are not permanent.
       
          g.setColor(Color.black);
          g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
                
       }  // end paint()
       
       
       private void putLine(int x1, int y1, int x2, int y2) {
              // Draw a line from (x1,y1) to (x2,y2) directly onto the
              // applet, without going through the paint() method.
           Graphics g = getGraphics();
           g.drawLine(x1,y1,x2,y2);
           g.dispose();
       }
       
       
       private void putPolygon() {
              // Draw the polygon described by the arrays xCoord and yCoord
              // and the integer pointCt.  A filled polygon with a black 
              // outline is drawn.  If pointCt is 0 or 1, nothing is drawn.
              // If pointCt is 2, only a black line is drawn.
           if (pointCt < 2)
              return;
           Graphics g = getGraphics();
           if (pointCt == 2) {
              g.drawLine(xCoord[0], yCoord[0], xCoord[1], yCoord[1]);
           }
           else {
              g.setColor(Color.red);
              g.fillPolygon(xCoord, yCoord, pointCt);
              g.setColor(Color.black);
              g.drawPolygon(xCoord, yCoord, pointCt);
           }
           g.dispose();
       }
       
    
       public void mousePressed(MouseEvent evt) { 
             // Process a user mouse-click.
       
          if (evt.isShiftDown()) {
                 // Clear the applet. (This only requires a repaint.)
                 // Also, set pointCt to zero to start a new polygon.
              pointCt = 0;
              repaint();
          }
          else if ( pointCt > 0 && (Math.abs(xCoord[0] - evt.getX()) <= 2)
                              && (Math.abs(yCoord[0] - evt.getY()) <= 2) ) {
                 // User has clicked near the starting point.
                 // Draw the polygon and reset pointCt so that the 
                 // user can start a new polygon.
             putPolygon();
             pointCt = 0;
          }
          else if (evt.isMetaDown() || pointCt == 500) {
                 // Draw the polygon and reset pointCt so that the 
                 // user can start a new polygon.
             putPolygon();
             pointCt = 0;
          }
          else {
                 // Add the point where the user clicked to the list of
                 // points in the polygon, and draw a line between the
                 // previous point and the current point.
             xCoord[pointCt] = evt.getX();
             yCoord[pointCt] = evt.getY();
             pointCt++;
             if (pointCt >= 2) {
                putLine(xCoord[pointCt-2], yCoord[pointCt-2], 
                             xCoord[pointCt-1], yCoord[pointCt-1]); 
             }
          }
          
       } // end mousePressed()
       
       public void mouseReleased(MouseEvent evt) { }
       public void mouseClicked(MouseEvent evt) { }
       public void mouseEntered(MouseEvent evt) { }
       public void mouseExited(MouseEvent evt) { }
    
    }  // end class SimplePolygons
 
0

Java Beograd
Novi Beograd

Član broj: 11890
Poruke: 9523
212.200.68.*



+10257 Profil

icon Re: HITNO potrebna main class09.12.2008. u 13:57 - pre 187 meseci
Šta zapravo hoćeš ?
OTPOR blokadi ulica, OTPOR blokiranom Beogradu, OTPOR blokiranoj Srbiji
 
0

anon81718

Član broj: 81718
Poruke: 24
92.241.158.*



Profil

icon Re: HITNO potrebna main class09.12.2008. u 14:05 - pre 187 meseci
Hocu kada kompajliram u netBeansu da mi se program pokrece u JFrame-u neke velicine 500x500...
i kad u njemu klikam znaci da mi se radi to shto code radi,crtash poligone,na mouse clicks
 
0

Java Beograd
Novi Beograd

Član broj: 11890
Poruke: 9523
212.200.68.*



+10257 Profil

icon Re: HITNO potrebna main class09.12.2008. u 14:31 - pre 187 meseci
Dobro ...
Izgleda da je vreme da naučiš i nešto van netBeans-a. A i red bi bio. Dakle, ovo je applet. Applet se izvršava u brawser-u. Da bi se to desilo, u kodu web stranice mora da postoji poseban applet tag. Za ovaj tvoj applet to bi, na primer, bilo sledeće

Code:

<html>
<applet code=SimplePolygons.class width=500 height=500>
</applet>
</html>


I onda, dakle, na isti folder smesti class fajl dobijen prevođenjem java koda koji si naveo, i napavljeni html, i onda je potreban samo dvoklik, i dobićeš applet koji posle nešto crtanja može da izgleda ovako:

OTPOR blokadi ulica, OTPOR blokiranom Beogradu, OTPOR blokiranoj Srbiji
Prikačeni fajlovi
 
0

anon81718

Član broj: 81718
Poruke: 24
92.36.246.*



Profil

icon Re: HITNO potrebna main class09.12.2008. u 21:13 - pre 187 meseci
OK...to je ok,to znam...cisti html tag za browser i deklaracija applet-a...ali meni treba za JFrame...kao windows aplikacija a ne net...

Ako moze bilo bi mi drago...mozda cak treba raditi neke izmjene u kodu...ako ne moze...isto ok....

Hvala u svakom slucaju... ;)

 
0

bantu

Član broj: 38670
Poruke: 305
89.111.240.*



+27 Profil

icon Re: HITNO potrebna main class10.12.2008. u 07:30 - pre 187 meseci
Jesi li pokušao sa:
Code:
appletviewer WebStranicaSaAppletom.htm
 
0

Java Beograd
Novi Beograd

Član broj: 11890
Poruke: 9523
212.200.68.*



+10257 Profil

icon Re: HITNO potrebna main class10.12.2008. u 08:52 - pre 187 meseci
Citat:
NENO_ROCK: ...ali meni treba za JFrame...kao windows aplikacija a ne net...

E pa onda nisi trebao da pišeš applet, već frame. Ili, ti to nisi ni pisao, već si negde našao kod, a pojma nemaš šta gde radi ?

OTPOR blokadi ulica, OTPOR blokiranom Beogradu, OTPOR blokiranoj Srbiji
 
0

anon81718

Član broj: 81718
Poruke: 24
92.36.251.*



Profil

icon Re: HITNO potrebna main class11.12.2008. u 14:41 - pre 187 meseci
HaHaHa

Po ko zna koji put sam se uvjerio da ovaj forum nema veze s vezom...valjda su tipovi ovakvih foruma napravljeni za edukaciju i pomoc drugima...
a ne za vrijedjanje i omalovazavanje drugih...nisam te pitao da mi govorish shta znam a shta ne znam,meni je bilo potrebno hitno pa sam zamolio iskusnije da mi pomognu,a tvoje je ako znash pomozi a ako ne znash vrati se sa thread-a i gledaj svoja posla...i josh neshto ako ne znash o cemu se radilo i ako nisi znao da napravish evo ti cijeli zadatak koji sam napravio i to je bilo to shto sam trazio,nishta strashno ali eto na zalost nisam imao vremena ...ja se izvinjavam shto sam pitao ikako na ovim forumima...najbolji je majstor "uradi sam"...
hvala josh jednom na malkice pomoci...

Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author NENO_ROCK
 */
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class Zadatak
{
    
    public static void main (String[] args)
    {
        JFrame frame = new JFrame("Zadatak (NENO_ROCK)");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(new DrawingPanel());
        frame.pack();
        frame.setVisible(true);
    }
}


class DrawingPanel extends JPanel
implements MouseListener, MouseMotionListener
{

    private static final Dimension PREF_DIM = new Dimension(600, 600);
    
    private boolean polygonIsNowComplete = false;
    
    private final Point trackPoint = new Point();
    
    private ArrayList points = new ArrayList();

    
    DrawingPanel()
    {
        super();
        addMouseListener(this);
        addMouseMotionListener(this);
    }
    
    
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        
        int numPoints = points.size();
        if (numPoints == 0)
            return; 
        
        Point prevPoint = (Point) points.get(0);
        
        
        Iterator it = points.iterator();
        while (it.hasNext())
        {
            Point curPoint = (Point) it.next();
            draw(g, prevPoint, curPoint);            
            prevPoint = curPoint;
        }
        
        
        if (polygonIsNowComplete)
            draw(g, prevPoint, (Point) points.get(0));
        else
            draw(g, prevPoint, trackPoint);    
    }
    
    
    public void mouseClicked(MouseEvent evt)
    {
        int x = evt.getX();
        int y = evt.getY();
        
        switch (evt.getClickCount())
        {
            case 1: 
                if (polygonIsNowComplete)
                {
                    points.clear();
                    polygonIsNowComplete = false;
                }
                points.add(new Point(x, y));
                repaint();
                break;

            case 2: // double-click
                polygonIsNowComplete = true;
                points.add(new Point(x, y));
                repaint();
                break;            
            
                
            default: 
                break;
        }
    }
    
    
    
    public void mouseMoved(MouseEvent evt)
    {
        trackPoint.x = evt.getX();
        trackPoint.y = evt.getY();
        repaint();
    }
    
    
    private void draw(Graphics g, Point p1, Point p2)
    {
        int x1 = p1.x;
        int y1 = p1.y;
            
        int x2 = p2.x;
        int y2 = p2.y;
        
        
        g.setColor(Color.black.darker());
        g.drawLine(x1 + 3, y1 + 3, x2 + 3, y2 + 3);        
    }
    
    
    public Dimension getPreferredSize()
    { return PREF_DIM; }
        
    public void mouseDragged(MouseEvent evt)
    { }
    
    public void mousePressed(MouseEvent evt)
    { }    
    
    public void mouseReleased(MouseEvent evt)
    { }    
    
    public void mouseEntered(MouseEvent evt)
    { }    
    
    public void mouseExited(MouseEvent evt)
    { }
}
 
0

[es] :: Java :: HITNO potrebna main class
(Zaključana tema (lock), by hyle)

[ Pregleda: 1771 | Odgovora: 7 ] > FB > Twit

Postavi temu

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.