home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2814
Discussions: 188,384, Posts: 2,243,509, Members: 232,615
Old April 23rd, 2003, 11:22 PM   Digg it!   #1 (permalink)
Best To Avoid Me
 
Martoch's Avatar
 
Join Date: Mar 2002
Location: Under Your Bed
Posts: 8,596
JAVA help needed badly!!!

Hi guys!


Ok, here's what I got going on...I'm doing a Java project that is a simple text based story/game with a few .gif images. My problem is that once my program gets to the part where the image is displayed, it won't go any further. My teacher mentioned something about having either an "OK" button to proceed or a timer, but I can't find out how to do that anywhere and it's really starting to frustrate me!


Here's my code so far.
NOTE: The program DOES NOT get past the image being displayed (the code in red, the image works just fine), so nothing beyond the Martoch.gif file is shown. The image just sits there with nothing to click.

public class Martoch extends JApplet {
private Image Martoch;
private Image Paladin;
private Image Sorcerer;


public void init() //begins method
{

//Explain purpose of this application
JOptionPane.showMessageDialog( null,
"Blah blah blah"
"Want to Play?",
JOptionPane.INFORMATION_MESSAGE );

//Show Martoch.gif
Martoch = getImage( getDocumentBase (), "Martoch.gif" );
}

public void paint( Graphics g )
{
g.drawImage( Martoch, 0, 0, this );

}


String fighterName;
String fighterCity;

fighterName = JOptionPane.showInputDialog( "Please enter your name" );
fighterCity = JOptionPane.showInputDialog( "Please enter the city you hail from" );

JOptionPane.showMessageDialog( null,
"Blah blah blah",
"It's time to choose",
JOptionPane.INFORMATION_MESSAGE );

So any thoughts on this? I'm so lost...

Thanks!
Mike
__________________
~ Camp Crystal Lake counselor positions opening daily ~

Martoch is online now   Reply With Quote
Old April 24th, 2003, 12:44 AM     #2 (permalink)
Best To Avoid Me
 
Martoch's Avatar
 
Join Date: Mar 2002
Location: Under Your Bed
Posts: 8,596
First bump...

Martoch is online now   Reply With Quote
Old April 24th, 2003, 07:28 AM     #3 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,020
maybe PM strangerstill I do believe he's a Java guy

vass0922 is online now   Reply With Quote
Old April 24th, 2003, 08:46 AM     #4 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 3,421
Quote:
public void paint( Graphics g )
{
g.drawImage( Martoch, 0, 0, this );

}
maybe a "repaint()" w/o the quotes could do it, if you want a new picture to be repainted. Also, if you have a button, you'd need implements ActionListener [where you have public class Martoch extends JApplet (you just type in implements ActionListener right after JApplet)] then
public void actionListener(ActionEvent e)
{
}

In school, we don't use private for the Images, we just use Image=whatever;
poopeyhed2 is offline   Reply With Quote
Old April 24th, 2003, 05:33 PM     #5 (permalink)
Best To Avoid Me
 
Martoch's Avatar
 
Join Date: Mar 2002
Location: Under Your Bed
Posts: 8,596
Quote:
Originally posted by poopeyhed2


maybe a "repaint()" w/o the quotes could do it, if you want a new picture to be repainted. Also, if you have a button, you'd need implements ActionListener
I'm not exactly sure what you mean by having a new picture "repainted". Basically, my program works fine without the images...but when I have an image load anywhere in the program, the program just stops right at the image. The image has no "OK" button to click to proceed or a 5-second timer until it goes away.


I do have buttons labeled Sorceror and Paladin that the user can click to select which fighter they want...the buttons point to methods of course. I did have to add the "implements ActionListener" to the extends JApplet of course.

Thanks for your help though, I learned about the buttons last night...you were right on the money there.
Martoch is online now   Reply With Quote
Old April 24th, 2003, 05:54 PM     #6 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 3,421
Sorry, I must have mis read that the repaint() method refreshes everything that you see, which was what I was originally thinking, where your first picture comes up and then you don't see any other picture after that.

Sorry I ca'nt be that much help, as I too am a newbie in Java.. In school, we use BlueJ, seems like a pretty good piece of software, and especially that it's free
poopeyhed2 is offline   Reply With Quote
Old April 24th, 2003, 07:15 PM     #7 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
(I reckon this ought to be a sticky on this forum, but) USE THE CODE TAG!

You're indenting your code (I'm hoping) in the Allman style (I'm a 1TBS man, but I learnt C from K&R) - so post using the CODE tag so it shows up in your post! - it took me ages to realise what's wrong with your code precisely because it's not indented!

Oh, you wanna know what *is* wrong with it? Everything after the paint() method is in the class block instead of a method block (next indent level) so it doesn't get regarded as executable code, so of course it doesn't get run.

You're running the applet from the init thread - this is A Bad Thing but it could work for now. To get the image to show and then continue with your code you need to keep the code in one uninterrupted method and place a repaint() or similar call at the relevant point in the code:
Code:
                Martoch = getImage(getDocumentBase (), "Martoch.gif");
                repaint();
                String fighterName;
Do they actually teach you the philosophy of object oriented programming before throwing you in and making you write code? Your code above would make sense in a run-time, dynamically typed language like JavaScript, but Java is a lot less sloppy...
strangerstill is offline   Reply With Quote
Old April 24th, 2003, 10:40 PM     #8 (permalink)
Member
 
DJDaveMark's Avatar
 
Join Date: Feb 2003
Location: France
Posts: 55
Hey Martoch,

I got your code working by changing it to the following
Code:
import java.applet.*;
import java.awt.*;
import javax.swing.*;

public class Martoch extends JApplet
{
    private Image Martoch;
    private Image Paladin;
    private Image Sorcerer;
    
    public void init() //begins method
    {
        //Show Martoch.gif
        Martoch = getImage( getDocumentBase (), "Martoch.gif" );
    }
    
    public void start()
    {
        //Explain purpose of this application JOptionPane.showMessageDialog( null, "Blah blah blah",
        "Want to Play?", JOptionPane.INFORMATION_MESSAGE );
        
        String fighterName = JOptionPane.showInputDialog( "Please enter your name" );
        String fighterCity = JOptionPane.showInputDialog( "Please enter the city you hail from" );

        JOptionPane.showMessageDialog( null, "Blah blah blah",
        "It's time to choose", JOptionPane.INFORMATION_MESSAGE );
    }
    
    public void paint( Graphics g )
    {
        g.drawImage( Martoch, 0, 0, this );
    }
}
Is that any help / wot u wanted?
DJDaveMark is offline   Reply With Quote
Old April 24th, 2003, 10:43 PM     #9 (permalink)
Best To Avoid Me
 
Martoch's Avatar
 
Join Date: Mar 2002
Location: Under Your Bed
Posts: 8,596
Ok I'm sort of following you and I'm very appreciative of your help!


However, this is my current code:

Code:
    public void init()  //begins method
    {                
        
        //Explain purpose of this application
        JOptionPane.showMessageDialog( null, 
                "Think you have what it takes" + 
                "\n to survive in the dark realm of Sylox?" +
                "\nMuhahahaha...think again my young friend." +
                "\nMany a warrior has stepped forward with" +
		    "\nheavy hand and brave heart...combining" +
		    "\ncourage and strength in an attempt to" +
		    "\nrelease the world from HIS mighty grip" +
                "\nAll have failed...HE is an unmatched force," +
                "\nseemingly immortal...can you defeat HIM?" +
		    "\nWho is HE, you ask...why, you shall soon see.",
                "Want to Play?", 
                JOptionPane.INFORMATION_MESSAGE );

		Martoch = getImage( getDocumentbase(), "Martoch.gif");
		repaint();	
	

	String fighterName;
Ignore the indentations in the showMessageDialog code, it all lines up in notepad. Well now when I try to compile it I get a "Cannot resolve symbol" error with the little arrow pointing to the g in getDocumentbase.
I'm terribly sorry if I'm being very "Java stupid" right now, but this is actually more advanced than we got in the class. I just really want my image to show up, then somehow be able to continue on with my code.

So, what am I doing wrong now?

EDIT: trying your code now!!!
THANKS!

Last edited by Martoch : April 24th, 2003 at 10:50 PM.
Martoch is online now   Reply With Quote
Old April 24th, 2003, 10:56 PM     #10 (permalink)
Best To Avoid Me
 
Martoch's Avatar
 
Join Date: Mar 2002
Location: Under Your Bed
Posts: 8,596
Quote:
Originally posted by DJDaveMark
Hey Martoch,

I got your code working by changing it to the following[code}[/code]Is that any help / wot u wanted?
Well the only "issue" with that code is that the image isn't displayed until the end of the applet...I need it to be displayed in the middle of the applet, then go away so the rest of the text can be shown and the code can continue.
Clear as mud?
Martoch is online now   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2896)
CPU wont boot (6)
3-days in and no threads about Gaza (160)
The United States Debt (20)
I think I just killed my computer w.. (24)
hp compaq nc6000 problems (139)
Upgrading RAM (5)
Folderchat Weekday thread (442)
Antec 300 bulk purchase? (11)
Recent Discussions
CPU wont boot (6)
GLaDOS is up. (3)
HP notebook reinstall Vista NO .. (5)
Building a gaming computer advi.. (4)
hp compaq nc6000 problems (139)
Folderchat Weekday thread (442)
Creative T-3000 Subwoofer (3)
ACPI controller halt on boot (2)
Worth the upgrade?? (15)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 10:39 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



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