java - Eclipse Bug on My PC only -
the code works on of other pc's have used before, , after, reasons when run on computer has odd bug.
when click on square , circle new colour of square clicked on become colour of background circle clicked on, not fill of circle actual background.
also when circle clicked on first time there outline of blue circle right of circle clicked on.
please need can code on computer, , able coursework. have switched between computers use 1.6 , 1.7 , changed them work, , okay. have seen pc, have updated of java programs can (jdk, drivers graphics card, eclipse) cant seem figure out.
import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.event.mouseevent; import java.awt.event.mouselistener; import java.awt.geom.ellipse2d; import java.awt.geom.rectangle2d; import java.awt.geom.rectangularshape; import java.awt.graphics2d; import java.util.random; import javax.swing.*; public class part2 extends jframe { public static void main(string[] args) { part2 window = new part2("shape colour"); window.setdefaultcloseoperation(jframe.exit_on_close); } public part2(string title) { super(title); //adds circle , square objects new panel jpanel = new jpanel(); this.setcontentpane(all); this.setsize(900, 200); this.setresizable(true); all.setlayout(new gridlayout()); all.add(new circle()); all.add(new rectangle()); all.add(new circle()); all.add(new rectangle()); all.add(new circle()); setvisible(true); } abstract class shape extends jpanel { random random = new random(); rectangularshape shape; color color; //creates shape of random "colour" (notice "u"), , adds mouselistener public shape() { super(); //this.setsize(); randomcolor(); this.addmouselistener(new shapelistener(this)); } //decided how paint shape, , fill 1 colour //names each shape "thing" public void paintcomponent(graphics g) { super.paintcomponents(g); graphics2d thing = (graphics2d) g; thing.setcolor(color); thing.fill(shape); } //makes random colour form possible combinations of colour private void randomcolor() { this.color = new color(random.nextint(256), random.nextint(256),random.nextint(256)); } class shapelistener implements mouselistener { jpanel shapepanel; int mousex; int mousey; //shapepanel constructor public shapelistener(jpanel shapepanel) { this.shapepanel = shapepanel; } public void mouseentered(mouseevent e) {} public void mouseexited(mouseevent e) {} public void mousepressed(mouseevent e) {} public void mousereleased(mouseevent e) {} public void mouseclicked(mouseevent e) { //gets mouse coordinates mousex = e.getx(); mousey = e.gety(); //if click within area of shape @ coordinates repaint, random colour if (shape.contains(mousex, mousey)) { randomcolor(); shapepanel.repaint(); } } } } //method creating circle class circle extends shape { public circle() { super(); this.shape = new ellipse2d.double(10, 10, 150, 150); } } //and square class rectangle extends shape { public rectangle() { super(); this.shape = new rectangle2d.double(10, 10, 150, 150); } } }
Comments
Post a Comment