JavaScript is required to use Bungie.net

OffTopic

Surf a Flood of random discussion.
Edited by colbyrules8: 9/11/2013 5:16:40 PM
4

Java programming question.

Below I am going to post my code and it should be a simple solution if you are past 1302 or have general knowledge of Java. We are making a program that utilizes Jframe and every time you click a square is made and squares are made when you click and drag. The major portion is re-sizing all of the squares based on which direction the wheel of the mouse is spun. The program , as of now, works fine if you want to make every square larger or smaller but the project requires the final square that is brought into the jframe to be the only one that is able to be changed. How would I go about doing that? [quote]100 pts - Add the ability to change the size of each box, so that every box you draw after scrolling the mouse wheel is sized appropriately. HINT: You'll need an array of int sizes that keeps track of the size of each point in the pointsList (for up to, say, 10000 boxes) - remember to change the drawing loop (fillRect will need new parameters) and the mouseDragged listener (that's where you'll set the size for each new box). 110 pts - Add four filled rectangles to the side or bottom of your panel with four different colors the user can click on to change the color of subsequent boxes drawn on the screen. HINT: You'll need an array of Color objects similar to your array of int[] sizes above, and change the drawing loop in addition to the mousePressed and mouseDragged listeners....[/quote] [quote]import java.util.ArrayList; import javax.swing.JPanel; import java.awt.*; import java.awt.event.*; public class SquaresPanel extends JPanel { private int SIZE = 10; // radius of each square private ArrayList<Point> pointList; private double LAST = 0; //----------------------------------------------------------------- // Constructor: Sets up this panel to listen for mouse events. //----------------------------------------------------------------- public SquaresPanel() { super(); pointList = new ArrayList<Point>(); addMouseListener (new SquaresListener()); addMouseMotionListener (new SquaresListener()); addMouseWheelListener (new SquaresListener()); setBackground (new Color( (float)Math.random(), (float)Math.random(), (float)Math.random())); setPreferredSize (new Dimension(800, 600)); } //----------------------------------------------------------------- // Draws all of the squares stored in the list. //----------------------------------------------------------------- public void paintComponent (Graphics page) { super.paintComponent(page); page.setColor (Color.WHITE); for (Point spot : pointList) { page.setColor(new Color( (float)Math.random(), (float)Math.random(), (float)Math.random())); page.fill3DRect(spot.x-SIZE, spot.y-SIZE, SIZE*2, SIZE*2, true); LAST = pointList.size(); } page.drawString ("Count: " + pointList.size(), 5, 15); } //***************************************************************** // Represents the listener for mouse events. //***************************************************************** private class SquaresListener implements MouseListener, MouseMotionListener, MouseWheelListener { //-------------------------------------------------------------- // Adds the current point to the list of points and redraws // the panel whenever the mouse button is pressed. //-------------------------------------------------------------- public void mousePressed (MouseEvent event) { if (event.getButton() == MouseEvent.BUTTON1) pointList.add(event.getPoint()); // I've just added the "nth" point // so "remember" the n'th point's size repaint(); } //-------------------------------------------------------------- // Provide empty definitions for unused event methods. //-------------------------------------------------------------- public void mouseClicked (MouseEvent event) {} public void mouseReleased (MouseEvent event) {} public void mouseEntered (MouseEvent event) {} public void mouseExited (MouseEvent event) {} public void mouseDragged(MouseEvent event) { pointList.add(event.getPoint()); repaint(); } public void mouseMoved(MouseEvent event) {} public void mouseWheelMoved(MouseWheelEvent event) { SIZE -= 3* event.getWheelRotation(); repaint(); } } }[/quote]

Posting in language:

 

Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

  • ………….....……...- *" \ - "::*'\ ………...……„-^*'' : : „'' : : : :: *„ ……....…..„-* : : :„„--/ : : : : : : : '\ ……....…./ : : „-* . .| : : : : : : : : '| ……......./ : „-* . . . | : : : : : : : : | …….......\„-* . . . . .| : : : : : : : :'| ……....../ . . . . . . '| : : : : : : : :| …......../ . @ . .@. .'\ : : : : : : : | …......./ . . . . . . . . . .\ : : : : : : :| …...../ . . . . . . . . . . . '\ : : : : : / ….../ . . . \____/ . . . ….*-„„„„-*' ….'/ . . . . . . . . . . . . . . '| …/ . . . . . . . ./ . . . . . . .| ../ . . . . . . . .'/ . . . . . . .'| ./ . . . . . . . . / . . . . . . .'| '/ . . . . . . . . . . . . . . . .'| '| . . . . . \ . . . . . . . . . .| '| . . . . . . \„_^- „ . . . .'| '| . . . . . . . . .'\ .\ ./ '/ . | | .\ . . . . . . . . . \ .'' / . '| | . . . . . . . . . . / .'/ . . .| | . . . . . . . . . . / .'/ . . . | | .\ . . . . . . . . . \ .'' / . '| '| . . . . . . . . .'\ .\ ./ '/ . | '| . . . . . . \„_^- „ . . . . .'| '| . . . . . \ . . . . . . . . . .| ./ . . . . . . . . / . . . . . . .'| ../ . . . . . . . .'/ . . . . . . .'| …/ . . . . . . . ./ . . . . . . .| ….'/ . . . . . . . . . . . . . . '| ….../ . . . . . . . . . . . . . *-„„„„-*' ……./ . . . . . . . . . . . '\ : : : : : / ……../ . . . . . . . . . .\ : : : : : : :| ……..../ . . . . . . . .'\ : : : : : : : | ……….../ . . . . . . '| : : : : : : : :| ………...\„-* . . . . .| : : : : : : : :'| ……….../ : „-* . . . | : : : : : : : : | ……….../ : „-* . . . | : : : : : : : : | …………..„-* : : :„„--/ : : : : : : : '\ ………………„-^*'' : : „'' : : : :: *„ …………………...- *" \ - "::*'\

    Posting in language:

     

    Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

  • As you know I don't know java, but I'll look at it.

    Posting in language:

     

    Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

  • I am not that good at java (I suck to be honest) but Ill run your code through JCreator when I get to school tomorrow if you want and check for bugs.

    Posting in language:

     

    Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

    2 Replies
    • Nothing?

      Posting in language:

       

      Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

    You are not allowed to view this content.
    ;
    preload icon
    preload icon
    preload icon