Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Discussions / Miscellaneous Topics / Re: Anyone here play softball? on: 2008-07-09 01:57:16
True, but it always helps to have an interest in what you are working on.
2  Discussions / Miscellaneous Topics / Re: Anyone here play softball? on: 2008-07-09 01:06:42
I am looking for a developer that would be interested in working on a browser based HR derby game for slowpitch softball.

Similar to a stickbaseball.com or pinchhitter2 game only statistically realistic with wind effects.
3  Discussions / Miscellaneous Topics / Anyone here play softball? on: 2008-07-08 19:20:00
Anyone?
4  Discussions / Jobs and Resumes / Re: Demo could lead to a decent part time job on: 2008-07-08 04:21:00
No gambling involved.
5  Discussions / Jobs and Resumes / Demo could lead to a decent part time job on: 2008-07-08 00:30:16
I'm looking for a programmer to make a browser based homerun derby game with realistic results based on provided statistics.  Based on the results of this browser game, the programmer will be asked to build improved versions of the game and enhancements.

More info and specs by emailing sfdlw@yahoo.com
6  Game Development / Newbie & Debugging Questions / Re: Car on Track scrollable pane on: 2006-04-28 21:16:49
It is not null.
7  Game Development / Newbie & Debugging Questions / Re: Car on Track scrollable pane on: 2006-04-28 20:32:50
Thanks, actually I did do the Hello World first, so this is my second program.

Ok, I am now loading the image outside of the paintComponent and it still does not show up on the scrollpane.

This is the paintComponent of the scrollpane now.  The filloval and drawstring work fine but the drawimage does not?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
    public void paintComponent(Graphics g) {
      super.paintComponent(g); 
     
      if (img != null) {
        g.drawImage(img, 20, 20, null);
      } 
      else
      {    
       System.out.println("no img found");     
      }
      g.fillOval(10, 10, 10, 10);
      g.drawString("Wheres my GIF!", 20, 120);
     
    }
8  Game Development / Newbie & Debugging Questions / Car on Track scrollable pane on: 2006-04-28 17:13:11
Hello, this is my first java program.  I am attempting to get a racecar gif to show up on my scrollable pane racetrack gif.  Here is my  code.  The track shows up in the scrollable pane but the car does not.  Any direction would be greatly appreciated.

It looks like I need to add something to the paintcomponent of ScrollablePicture.  When I add a circle like this it draws it:
1  
2  
3  
4  
5  
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);  
      img = getToolkit().createImage("00Flames0.gif");
      g.fillOval(10, 10, 10, 10);
    }


When I go to change the oval to a draw image, it draws nothing?
1  
2  
3  
4  
5  
6  
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);  
      img = getToolkit().createImage("00Flames0.gif");
/*      g.fillOval(10, 10, 10, 10);*/
      g.drawImage(img, 10, 10, this);
    }


Thank you,
Dale



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
package CarOnTrack;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Canvas;
import javax.swing.JLabel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.image.*;
import java.net.*;
import javax.imageio.*;


public class CarOnTrack extends JPanel
    private JPanel mainPanel;
    private JLabel imageLabel;
 
  public CarOnTrack (){  
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new JFrame("CarOnTrack");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
       
    JPanel panel = (JPanel)frame.getContentPane();
   
    ScrollDemo trackscrollable = new ScrollDemo();
   
    mainPanel = new JPanel();
    Icon myIcon = new ImageIcon("00Flames0.gif");
    imageLabel = new JLabel(myIcon);
    mainPanel.add(imageLabel);
    mainPanel.setVisible(true);
    trackscrollable.add(mainPanel,1,1);
   
    panel.add(trackscrollable);
    frame.setBounds(0,0,500,300); 
    frame.setVisible(true);
  }

  public static void main(String[] args)
  {   
     System.out.println("BEGIN PROGRAM");
     CarOnTrack cot = new CarOnTrack();
     System.out.println("END PROGRAM");     
  }
}
package CarOnTrack;

import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.*;

public class ScrollDemo extends JPanel {
    private ScrollablePicture picture;
    private ScrollablePicture picture2;
    Image trackgif;
       
    public ScrollDemo() {
        setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

        //Get the image to use.
        ImageIcon trackgif = createImageIcon("Daytona.gif");
       
        //Set up the scroll pane.
        picture = new ScrollablePicture(trackgif, 1);
        JScrollPane pictureScrollPane = new javax.swing.JScrollPane(picture);
        pictureScrollPane.setPreferredSize(new Dimension(200, 100));
        pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black));
       
        add(pictureScrollPane);
        setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
    }
     
    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = ScrollDemo.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

     public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
            }
        });
    }
}
package CarOnTrack;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ScrollablePicture extends JLabel
                               implements Scrollable,
                                          MouseMotionListener {

    private int maxUnitIncrement = 1;
    private boolean missingPicture = false;

    public ScrollablePicture(ImageIcon i, int m) {
        super(i);
        if (i == null) {
            missingPicture = true;
            setText("No picture found.");
            setHorizontalAlignment(CENTER);
            setOpaque(true);
            setBackground(Color.white);
        }
        maxUnitIncrement = m;

        //Let the user scroll by dragging to outside the window.
        setAutoscrolls(true); //enable synthetic drag events
        addMouseMotionListener(this); //handle mouse drags
    }

    //Methods required by the MouseMotionListener interface:
    public void mouseMoved(MouseEvent e) { }
    public void mouseDragged(MouseEvent e) {
        //The user is dragging us, so scroll!
        Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
        scrollRectToVisible(r);
    }

    public Dimension getPreferredSize() {
        if (missingPicture) {
            return new Dimension(320, 480);
        } else {
            return super.getPreferredSize();
        }
    }

    public Dimension getPreferredScrollableViewportSize() {
        return getPreferredSize();
    }

    public int getScrollableUnitIncrement(Rectangle visibleRect,
                                          int orientation,
                                          int direction) {
        //Get the current position.
        int currentPosition = 0;
        if (orientation == SwingConstants.HORIZONTAL) {
            currentPosition = visibleRect.x;
        } else {
            currentPosition = visibleRect.y;
        }

        //Return the number of pixels between currentPosition
        //and the nearest tick mark in the indicated direction.
        if (direction < 0) {
            int newPosition = currentPosition -
                             (currentPosition / maxUnitIncrement)
                              * maxUnitIncrement;
            return (newPosition == 0) ? maxUnitIncrement : newPosition;
        } else {
            return ((currentPosition / maxUnitIncrement) + 1)
                   * maxUnitIncrement
                   - currentPosition;
        }
    }

    public int getScrollableBlockIncrement(Rectangle visibleRect,
                                           int orientation,
                                           int direction) {
        if (orientation == SwingConstants.HORIZONTAL) {
            return visibleRect.width - maxUnitIncrement;
        } else {
            return visibleRect.height - maxUnitIncrement;
        }
    }

    public boolean getScrollableTracksViewportWidth() {
        return false;
    }

    public boolean getScrollableTracksViewportHeight() {
        return false;
    }

    public void setMaxUnitIncrement(int pixels) {
        maxUnitIncrement = pixels;
    }
}
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (74 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!