Προς το περιεχόμενο

Προτεινόμενες αναρτήσεις

Δημοσ.

tr3q..

 

 

 

ΛΟΛ. Σόρρυ! Μόλις είδα τον τίτλο και λες Java πρόβλημα!!! χαχαχαχαχαχααχ έλεος είμαι.. σόρρυ!

 

 

 

Βάλτα σε μία γραμμή.

 

Αν και είναι λάθος αυτό που πας να κάνεις, όπως πας να το κάνεις. Εάν θες, μπορείς να πεις ακριβώς τι θες να πετύχεις και να βοηθηθείς.

Δημοσ.

Edit--

 

Ότι είπε ο από πάνω αλλιώς:

 

>
class FigureEditor{
public FigureEditor()
{
	int[] a;
	a = new int[5];
}
}

 

 

Όντως θα βοηθούσε περισσότερο αν ξέραμε τι θέλεις να κάνεις :P

Δημοσ.

Δοκίμασε

 

>
class FigureEditor{
public FigureEditor()
{
	int[] a;
	a = new int[5];
}
}

 

Ναι αλλά έτσι απλά αρχικοποιεί το μέγεθος ενός int array (και τις τιμές του, λόγω Java) που όμως μένει "ξεκρέμαστος".

 

Όπως το είχε αρχικά, προσωπικά, πιστεύω ότι θέλει να είναι κάτι σαν "class feature" αλλά δεν μπορώ να καταλάβω τι ακριβώς θέλει.

 

>class FigureEditor{
int[] a;                    --------------------------------------- Syntax error on token ";", , expected
	{a = new int[5];}
}

τωρα δουλευει...

 

 

Μπορεί... αλλά είναι λάθος!!!!!!!!!!!

 

Βάλε κάτι από κάτω από το block που έφτιαξες και δες την τιμή του a αφού βγει από το block...

Δημοσ.

Ναι αλλά έτσι απλά αρχικοποιεί το μέγεθος ενός int array (και τις τιμές του, λόγω Java) που όμως μένει "ξεκρέμαστος".

 

Όπως το είχε αρχικά, προσωπικά, πιστεύω ότι θέλει να είναι κάτι σαν "class feature" αλλά δεν μπορώ να καταλάβω τι ακριβώς θέλει.

 

Ε δεν υποτίθεται πως θα το κάνει και κάτι? it's up to him :P

Δημοσ.
στο plgn.java κατω κατω: φτιαξτε ενα προγραμμα (πχ class FigureEditor) το οποιο δημιουργει μερικα Figures και τα σχεδιαζει. επισης φτιαξτε ενα Array Figure[] στο οποιο θα αποθηκευτουν τα Figures.

 

Turtles.java : (μας το εδωσε ετοιμο)

 

package turtles;

 

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics;

import java.util.List;

import java.util.Vector;

 

import javax.swing.JComponent;

import javax.swing.JFrame;

 

//import turtles.Turtles.Line;

 

/**

* Class Turtles implements a turtles graphics. The turtle is a point which has

* a x/y-position, a direction and a pen up/down state. Methods such as move,

* left, right are used to move the turtle and, depending on the pen state, to

* draw.

*

* Turtle Graphics are known from the Logo programming language.

*

* The Graphics Turtle is a cursor that has a position (X and Y coordinates), a

* heading and a pen up/down state. Procedures such as forward, left, etc are

* used as drawing idioms.

*

* @author Dominik Gruntz

*

*/

@SuppressWarnings("serial")

public class Turtles {

private static boolean down = false;

private static int x, y, direction;

private static Color color = Color.BLACK;

private static List<Line> lines = new Vector<Line>();

 

private static JFrame frame = new JFrame();

 

static {

frame.add(new JComponent() {

@Override

public void paint(Graphics g) {

synchronized(lines) {

for (Line line : lines) {

g.setColor(line.color);

g.drawLine(line.x1, line.y1, line.x2, line.y2);

}

}

}

});

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(new Dimension(400, 400));

}

 

private static class Line {

private int x1, y1, x2, y2;

private Color color;

 

public Line(int x1, int y1, int x2, int y2, Color color) {

this.x1 = x1;

this.y1 = y1;

this.x2 = x2;

this.y2 = y2;

this.color = color;

}

}

 

public static void setColor(Color c) {

color = c;

}

 

/**

* Shows the graphics window.

*/

public static void show() {

frame.setVisible(true);

}

 

/**

* Hides the graphics window.

*/

public static void hide() {

frame.setVisible(false);

}

 

/**

* Clears the graphics window.

*/

public static void clear() {

lines.clear();

frame.repaint();

}

 

/**

* Sets the pen state in down position. Moving the turtle will draw and

* change its position.

*/

public static void down() {

down = true;

}

 

/**

* Sets the pen state in up position. Moving the turtle will not draw, just

* change its position.

*/

public static void up() {

down = false;

}

 

/**

* Changes the direction of the turtle to the left (counterclockwise).

*

* @param angle

* the angle in degree the turtle turns.

*

*/

public static void left(int angle) {

direction -= angle;

}

 

/**

* Changes the direction of the turtle to the right (clockwise).

*

* @param angle

* the angle in degree the turtle turns.

*

*/

public static void right(int angle) {

direction += angle;

}

 

/**

* Moves the turtle in the current direction. The pen state determines

* whether the turtle draws or not.

*

* @param distance

* the distance the turtle moves, may be negative.

* @see down

* @see up

*/

public static void move(int distance) {

int x1 = x

+ (int) Math.round(Math.cos(direction * Math.PI / 180)

* distance);

int y1 = y

+ (int) Math.round(Math.sin(direction * Math.PI / 180)

* distance);

if (down) {

lines.add(new Line(x, y, x1, y1, color));

}

x = x1;

y = y1;

frame.repaint();

}

 

public static void move2(int x, int y, int x1, int y1) {

 

if (down) {

lines.add(new Line(x, y, x1, y1, color));

}

frame.repaint();

}

 

public static void move3(int x, int y, int x1, int y1, Color color) {

 

if (down) {

lines.add(new Line(x, y, x1, y1, color));

}

frame.repaint();

}

 

/**

* Moves the turtle to the specified point. The pen state determines whether

* the turtle draws or not. This method does not change the direction of the

* turtle.

*

* @param x

* x-coordinate of the new position

* @param y

* y-coordinate of the new position

*/

public static void moveTo(int x, int y) {

if (down) {

lines.add(new Line(Turtles.x, Turtles.y, x, y, color));

}

Turtles.x = x;

Turtles.y = y;

frame.repaint();

}

 

/**

* Sets the direction. The angle is specified in degrees (0..360). A

* direction of zero means moving to the right.

*

* @param angle

*

*/

public static void setDirection(int angle) {

direction = -angle;

}

 

 

}

 

 

 

 

ηθελα να φτιαξω το Figure[] αλλα μου εβγαζε errors και ετσι ηθελα να δοκιμασω πρωτα με κατι πιο απλο δλδ int[] για να δω τι φταιει...

 

 

γιατι δεν φαινεται στοιχισμενο οπως πριν??

 

 

plgn.java : (το εγραψα εγω)

 

package turtles;

 

import java.awt.Color;

 

import turtles.Turtles;

 

public class plgn {

public static void main(String[] args) {

PolygonTest();

}

 

public static void PolygonTest(){

Point poi[];

poi = new Point[13];

 

for(int i = 0; i<13; i++){

poi = new Point();

}

 

int x1,x2,x3,x4,y1,y2,y3,y4;

x1=165;

x2=200;

x3=230;

x4=265;

y1=110;

y2=140;

y3=170;

y4=200;

 

//Schweizerkreuz Punkte

 

poi[0].x =x2; //1

poi[0].y =y4;

 

poi[1].x =x3; //2

poi[1].y =y4;

 

poi[2].x =x3; //3

poi[2].y =y3;

 

poi[3].x =x4; //4

poi[3].y =y3;

 

poi[4].x =x4; //5

poi[4].y =y2;

 

poi[5].x =x3; //6

poi[5].y =y2;

 

poi[6].x =x3; //7

poi[6].y =y1;

 

poi[7].x =x2; //8

poi[7].y =y1;

 

poi[8].x =x2; //9

poi[8].y =y2;

 

poi[9].x =x1; //10

poi[9].y =y2;

 

poi[10].x =x1; //11

poi[10].y =y3;

 

poi[11].x =x2; //12

poi[11].y =y3;

 

poi[12].x =x2; //13

poi[12].y =y4;

 

Polygon swkrz;

swkrz = new Polygon(poi);

Polygon.drawPolygon(swkrz);

}

 

 

}

 

class Point{

int x;

int y;

 

public Point(){

this.x = 11;

this.y = 22;

}

}

 

class Figure{

private Color color;

private int x, y;

 

public void setX(int x){

this.x = x;

}

public void setY(int y){

this.y = y;

}

public void setColor(Color color){

this.color = color;

}

public int getX(){

return x;

}

public int getY(){

return y;

}

public Color getColor(){

return color;

}

 

public Figure(){

x = 1;

y = 1;

color = Color.BLACK;

}

public Figure(int x, int y, Color color){

this.x=x;

this.y=y;

this.color=color;

}

 

public void move(int x, int y){

this.x +=x;

this.y +=y;

}

public void draw(){

Turtles.move3(x,y,x,y,color);

}

}

 

 

class Polygon extends Figure{

private Point[] points;

Color color = getColor();

 

public Polygon(Point[] points, Color color){

int len;

len = points.length;

this.points = new Point[len];

 

for(int i = 0; i < len; i++){

this.points = points;

}

 

this.color = color;

}

 

public Polygon(Point[] points){

int len;

len = points.length;

this.points = new Point[len];

 

for(int i = 0; i < len; i++){

this.points = points;

}

 

this.color = Color.BLACK;

}

 

public Polygon(Polygon p, int dx, int dy){

int len;

len = p.points.length;

 

for(int i = 0; i < len; i++){

p.points.x += dx;

p.points.y += dy;

}

}

 

public static void drawPolygon(Polygon p){

Turtles.show();

Turtles.moveTo(p.points[0].x,p.points[0].y);

Turtles.down();

Turtles.setColor(p.color);

 

int len;

len = p.points.length;

 

for(int i = 0; i<len-1; i++){

Turtles.move2(p.points.x, p.points.y, p.points[i+1].x, p.points[i+1].y);

}

}

}

 

class Circle extends Figure{

private int radio;

 

public void setRadio(int radio){

this.radio = radio;

}

 

public int getRadio(){

return radio;

}

 

public Circle(){

radio = 5;

}

 

public Circle(int x, int y,Color color, int radio){

super(x,y,color);

this.radio=radio;

}

 

@Override

public void draw(){

int x = getX();

int y = getY();

for(int i=0;i<=360;i++){

Turtles.moveTo(

(int)(x + radio*Math.cos(i/180.0*Math.PI)), (int)(y + radio*Math.sin(i/180.0*Math.PI)));

}

}

}

 

class Rectangle extends Figure{

private int width, height;

 

public void setWidth(int width){

this.width = width;

}

public void setHeight(int height){

this.height = height;

}

 

public int getWidth(){

return width;

}

public int getHeight(){

return height;

}

 

public Rectangle(){

width = 5;

height = 5;

}

 

public Rectangle(int x, int y,Color color, int width, int height){

super(x,y,color);

this.width = 5;

this.height = 5;

}

 

@Override

public void draw(){

int x = getX();

int y = getY();

Color color = getColor();

Turtles.move3(x,y,x+width,y,color);

Turtles.move3(x,y+height,x+width,y+height,color);

Turtles.move3(x,y,x,y+height,color);

Turtles.move3(x+width,y,x+width,y+height,color);

}

}

 

class FigureEditor{

int[] a;

{a = new int[5];}

{a[0] = 546;}

}

 

 

 

 

Δημοσ.

στο plgn.java κατω κατω: φτιαξτε ενα προγραμμα (πχ class FigureEditor) το οποιο δημιουργει μερικα Figures και τα σχεδιαζει. επισης φτιαξτε ενα Array Figure[] στο οποιο θα αποθηκευτουν τα Figures.

Μηπως αυτα τα δημιουργει σε μια main ή σε καποια αλλη μεθοδο?? ^_^

  • 3 εβδομάδες αργότερα...
Δημοσ.

> public class Main {
public static void main(String[] args) {
     .
     .
     .
     Stack.clear(); 		------>  Cannot make a static reference to the non-static method clear() from the type Stack
	.
   }
}	


class Stack{
 .
 .
 .
 public void clear(){              	-----> μετα το αλλαζω σε static και μου εμφανιζει τα παρακατω:
     	for(int i=0; i<100; i++){
     		this.array[i] = 0; 		-----> Cannot use this in a static context
     	}
 		this.index = 0;        	-----> Cannot use this in a static context
 	}
}

 

τι μπορω να κανω?

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...