Show Posts
|
|
Pages: [1]
|
|
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.
|
|
|
|
|
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.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 (){ JFrame.setDefaultLookAndFeelDecorated(true);
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));
ImageIcon trackgif = createImageIcon("Daytona.gif"); 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)); } 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;
setAutoscrolls(true); addMouseMotionListener(this); }
public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { 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) { int currentPosition = 0; if (orientation == SwingConstants.HORIZONTAL) { currentPosition = visibleRect.x; } else { currentPosition = visibleRect.y; }
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; } } |
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|