toomuchfreetime 0 Light Poster

Looks like you have the variables set up the wrong way around

#
public void setVarX( String X ){
#
X = VarX;}

Try it this way

#
public void setVarX( String X ){
#
 VarX = X ;}
toomuchfreetime 0 Light Poster

Anyone willing to give me a few points on my problem here. I would appreciate it very much. At the moment i think i will just stay with the java. But would like to know what everyone else thinks

Cheers
steve

toomuchfreetime 0 Light Poster

Hey are you using mysql command line utility? Your text looks out to me. there is no 'd' in mysqld.sock

i.e /var/run/mysqld/mysql.sock

Not

/var/run/mysqld/mysqld.sock

toomuchfreetime 0 Light Poster

It look to me like you have all the code you need in front of you.

Copy the 'setBase(double newBase)' method in the Triangle class and redo it so that it sets the height. as you are already passing in a value for height in the main.

toomuchfreetime 0 Light Poster

Mmm i don't think it works like that around here. How about you post your code and we can see then if we can help you with it.

toomuchfreetime 0 Light Poster

For me it probably would be as i have more experience with java. But i want to do this right and dont mind using an other language if it is the right path to go down.

I just need help in choosing which is the right path for me to go down.

Cheers
moutanna

toomuchfreetime 0 Light Poster

When you say reads do you mean reading from file or just a mistype? I think you mean read from an array. This can be done by checking each number in the array and seeing if they are devisable by 2. If they are then it is even other wise its an odd number.

use the modulus sign to work it out: %

toomuchfreetime 0 Light Poster

Thanks for your reply 0805638. I've programed with c as well in fact this year i'm using c in an opengl module and a real time system module. It's good but i prefer the more modern languages myself(java,c#). I've used java for just over 2 years, so there wont be any problem there(hopefully)

I'm going using jboss to set up a receiving socket for all the rfid reader scans that are sent and store and manipulate in the database.

But for the web based front end for all this data i want to create the floor plan of my scanning area and nice graphs for presentation purposes . I'll also be adding other functionallty as i go. My floor plan once designed will be populated with data collected for the rfid readers. i.e. how many times a certain person entered a room. Or follow a person around the floor plan for a day to see where they went.

But my main question now is what programming language will offer me the greatest ability to graphic present these ideas?. I myself am thinking( silver light or javafx) But am unsure. I need a little guidance.

Thanks
Stephen

toomuchfreetime 0 Light Poster

Hey all,

I'm doing my final year in collage and have come up with an idea of using rfid readers and chips to track peoples movement within a defined zone.

I've been told that i will be using JBoss but that hasn't been nailed down yet. What i need help with is what other programming language i should be using with this. I need a language that is very graphicial that could be using to map out the floor plan in a very presentable manner.

From what i know from just checking on the web is that silver light and javafx keep poping up. Also i know java itself has graphics functions but i dont think they would be as powerfull as the others(open for correction).

Also just to let ye know JBoss hasn't been pick yet so open for suggestions on this. (Just to muddy the water a bit more :) )

Thanks alot to all who viewed
Stephen

toomuchfreetime 0 Light Poster

Hey

I'm trying to get a splash screen going for my application but having a problem in finding the image once the splash screen is called it returns a null.

I'm trying to use the java standard 6 way where the splash screen is displayed before the jvm is started and is displayed until a swing or awt container is displayed.

if (splash == null) {
            System.out.println("SplashScreen.getSplashScreen() returned null");
            return;
        }

it fails at this point and returns null and continues on with the rest of the program as normal.

full code is as follows

package tree;


import java.awt.*;
import java.awt.event.*;

public class splashScreen extends Frame implements ActionListener {
    static void renderSplashFrame(Graphics2D g, int frame) {
        final String[] comps = {"foo", "bar", "baz"};
        g.setComposite(AlphaComposite.Clear);
        g.fillRect(130,250,280,40);
        g.setPaintMode();
        g.setColor(Color.BLACK);
        g.drawString("Loading "+comps[(frame/5)%3]+"...", 130, 260);
        g.fillRect(130,270,(frame*10)%280,20);
    }
    public splashScreen() {
        super("SplashScreen demo");
        setSize(500, 300);
        setLayout(new BorderLayout());
        Menu m1 = new Menu("File");
        MenuItem mi1 = new MenuItem("Exit");
        m1.add(mi1);
        mi1.addActionListener(this);

        MenuBar mb = new MenuBar();
        setMenuBar(mb);
        mb.add(m1);
        final SplashScreen splash = SplashScreen.getSplashScreen();
        
        if (splash == null) {
            System.out.println("SplashScreen.getSplashScreen() returned null");
            return;
        }
        Graphics2D g = (Graphics2D)splash.createGraphics();
        if (g == null) {
            System.out.println("g is null");
            return;
        }
        for(int i=0; i<100; i++) {
            renderSplashFrame(g, i);
            splash.update();
            try {
                Thread.sleep(200);
            }
            catch(InterruptedException e) {
            }
        }
        splash.close();
        setVisible(true);
        toFront();
    }
    public void actionPerformed(ActionEvent ae) {
        System.exit(0);
    }
    public static void main (String args[]) {
        splashScreen test = new splashScreen();
    }
}

The manifest code is

Manifest-Version: 1.0
Main-Class: tree/splashScreen
SplashScreen-Image: tree/splash.png

not sure …

toomuchfreetime 0 Light Poster

Hey

I'm building a application and using JTree to navigate between the functions. This is working but can't figure out how to set up the JTree to have different icons for each node.

I can have one default icon that gets rendered to each node or set up an icon for when it is opened or closed but can't set up individual icons.

any help would be welcomed.

toomuchfreetime 0 Light Poster

Hey
Was just wondering if there is a way to un-attach, Attachments in a thread?

Because i was having problem with my project and i put problem code up and an attachment of my hangman.java and NumberGame.java code which was more or less finished (Also got some great advise).
But on second thoughts was probably not a good idea as i don't want to be giving students like me a fully worked out answer with out putting in the effort themselves as this is a common question in software courses and also knowing that there are always people in these courses (ie my course) that would trail the net for days looking for code if it means that they don't have to write it.

I thought there would be an option to un-attach a file?

Thanks Stephen

toomuchfreetime 0 Light Poster

Look your right.

I was just saying when Trogan first posted the problem he supplied all the values for the array which led me too see that they were all positive. which led to my answer to that particular question.

toomuchfreetime 0 Light Poster

I'm having a really anoying problem with my picture display for a kids game. In the code supplyed i've only given the
PicPanel where the picture function is placed.
ButtonHandler where the listener is for the answeering of the questions &
NumberGame main class that imports the previously defined panels to the main.

My problem is this the game starts up everything works. guess the first number and if right then message displayed congratulating the user piclevel increased by 1. goes to refresh to new picture but in stead take the "picpan" out and no picture is displayed.

The "mainpan" then gets pushed up to a north layout when it was center. i.e. "picpan" disapears.

I know my object from PicPanel pic = new PicPanel(); disappears but not sure how to fix this bit.

My program is more or less done after this. It's the only thing holding me up. any bit of help will be much appreciated

I've currently done

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JTextField;
import javax.swing.event.* ;
import java.net.*;
import java.io.*;
import java.awt.Color;
import java.util.Random;
import java.net.URL;



/**
 *
 * @author Stephen
 */
public class NumberGame extends JFrame
{
     JLabel sumQ,picture,score,life,helpfile;
     JPanel picpan,mainpan,playerpan,helppan;
     protected int total, answeertotal,lives = 5,scores;
     protected int diffucultyLevel = 0, picLevel = 0, languageLevel = 0;
     JTextField answeer; 
     JButton hideHelp;
     boolean whichMessage = false;
     private Container c;
     private String[] difLevel ={"Easy", "Normal", "Hard"};
     private String[] difLanguage ={"English", "French", "German"};
     private JRadioButtonMenuItem[] difficulty;
     private JRadioButtonMenuItem[] language;
     JMenuItem help; …
toomuchfreetime 0 Light Poster

No as Trogan said the values were all positive then this bit of code works. And it will pick out the max number.

int max = 0;

for (int i = 0; i < array.length; i++)
{

   if(max < array[i])
   {
      max = array[i];
   }

}

Where if the array was full of negative numbers then you would initialize it like :

int max;

for (int i = 0; i < array.length; i++)
{

   if(max < array[i])
   {
      max = array[i];
   }

}

But you are right that it would be of a better industry standard not to initialize max to any value. That is if you are unsure with what values you would be dealing with.

toomuchfreetime 0 Light Poster

Try something like this. It should do the trick.

This is one of the basic control statements for assessing values in arrays.
Good luck.

max = 0;
            
            for (int i = 0; i < array.length; i++) 
            {
                if(max < array[i])
                {
                   max = array[i]; 
                }
            }

P.S. try and get min from the array now.

toomuchfreetime 0 Light Poster

Thanks a lot for that. I know the code is probably bad practice but you got to learn some way.
Answer was right in front of me!!! as you said just make it global.

Got JMenu working with different levels in it working now with phased picture display where you got to get 10 questions right before you see the whole picture.

Is there any tips you could give me for cleaning up my code etc??

Thanks anyway.

toomuchfreetime 0 Light Poster

well what i'm trying to do is keep each JPanel separate from the main program and define them there and then do the actions etc from the main.

I know it probilly is not right as i only starting off and don't expect to get the programming
standards right. but it seem to be working for me up until now.

public class ButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e) 
        {
            
            player update = new player();
            answeertotal = Integer.parseInt(answeer.getText( ));
            
            if(answeertotal == total)
            {
                JOptionPane.showMessageDialog(null,  "Correct","",JOptionPane.INFORMATION_MESSAGE);
                correction.reset();  // THIS WORKS FOR ME I CREATE AN INSTANCE OF MAINPANEL AND CALL THE RESET() METHOD WHICH AND NEW QUESTION ETC LOOK AT ATTACHMENTS FOR FULL PROGRAM
                update.updateScore();// THIS IS MENT TO UPDATE THE CURRENT SCORE WHICH IS THE score JLabel BY USING THE updateScore() METHOD IN THE player class
                
                
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Sorry your wrong" + answeertotal + "   "+ total ,"",JOptionPane.ERROR_MESSAGE);
                update.updatelife();
            }
        }
    }

Once the call has been made it goes to the updateScore() method and new score then goes to the int2str(); to get it displayable and finaly it suppose to append the new scor to the score JLabel score.setText(sco);

public void int2str()
        {
            lif = String.valueOf("Current lives : " + lives);
            sco = String.valueOf("Current score : " + scores);
        }
        
        public  void updateScore()
        {
            scores = scores + 10;
            int2str();
            score.setText(sco);
        }

not sure where i'm gone wrong. and ya extending the JPanel from each inner class is bad alright i'd say …

toomuchfreetime 0 Light Poster

Hey

Seem to be having a problem updating a JLabel updateScore() and don't seem to know why.
this is effecting my keeping score. I know it something small but for life of me can't figure it out.

Other JLabels have been up dated (see attachment for full programe)

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JTextField;
import javax.swing.event.* ;
import java.net.*;
import java.io.*;
import java.awt.Color;
import java.util.Random;


/**
 *
 * @author Stephen
 */
public class NumberGame extends JFrame
{
     JLabel sumQ,picture,score,life;
     JPanel picpan,mainpan,playerpan;
     protected int total, answeertotal,lives = 5,scores;
     JTextField answeer; 
     private Container c;
    
     MainPanel correction = new MainPanel();
     ButtonHandler handler = new ButtonHandler();
      
     
    NumberGame()
    {
        c = getContentPane();
	c.setBackground(Color.white);
	setSize(300,500);
	setLocation(250,100);
        c.setVisible(true);
        c.setBackground(Color.PINK);
        
        PicPanel pic = new PicPanel();
        JPanel picpan = new JPanel(); 
        picpan.add(pic);
 
        MainPanel pane = new MainPanel();
        JPanel mainpan = new JPanel();
        mainpan.add(pane);
        
        player status = new player();
        JPanel playerpan = new JPanel();
        playerpan.add(status);
     
        
        c.add(picpan,BorderLayout.NORTH);
        c.add(mainpan,BorderLayout.CENTER);  
        c.add(playerpan,BorderLayout.SOUTH);
    }
    
    public class ButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e) 
        {
            
            player update = new player();
            answeertotal = Integer.parseInt(answeer.getText( ));
            
            if(answeertotal == total)
            {
                JOptionPane.showMessageDialog(null, "Correct","",JOptionPane.INFORMATION_MESSAGE);
                correction.reset();
                update.updateScore();
                
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Sorry your wrong" + answeertotal + "   "+ total ,"",JOptionPane.ERROR_MESSAGE);
                update.updatelife();
            }
        }
    }
 
    class player extends JPanel
    {
        String lif,sco;
        
        player()
        {
            int2str();
            life = new JLabel(lif);
            add(life);
            score = new JLabel(sco);
            add(score);
        }
        
        public void int2str()
        {
            lif = String.valueOf("Current lives : " + lives);
            sco = String.valueOf("Current score : " + scores);
        }
        
        public  void updateScore()
        {
            scores = scores …
toomuchfreetime 0 Light Poster

Sorted it.

It was my own fault when you look at a problem for too long the obvious answer is overlooked on mycase.:$ the problem is i was calling the wrong term for my ActionListener. this was what i was doing

ButtonHandler ItemHandler = new ButtonHandler(); 
ButtonHandler handler = new ButtonHandler(); 

private class ItemHandler implements ActionListener
{
  //this is my radio
}

private class ButtonHandler implements ActionListener
{ 
  //this was Jbutton
}

But should have called the object ButtonHandler which i did do earler only forgot the other object for dealing with the a-z buttons was called

ButtonHandler handler = new ButtonHandler();

Which set up a conflict and tryed to apply JMenuRadio to a JButton which does not work and i could not figure out. until it jumped out at me .... just renamed it.

RadioHandler ItemHandler = new RadioHandler (); 
ButtonHandler ItemHandler = new ButtonHandler (); 

private class RadioHandler implements ActionListener
{
  //what ever
}
private class ButtonHandler implements ActionListener
{ 
  //this was Jbutton
}

THANK ALOT TO peter_budo :)

Your info was invaluable to me... Just took me a while to see my own mistake:$

toomuchfreetime 0 Light Poster

Globally declared

String[] difLevel ={"Easy", "Normal", "Hard"};
 JRadioButtonMenuItem[] difficulty;
 ButtonGroup radioGroup = new ButtonGroup();
 ButtonHandler ItemHandler = new ButtonHandler();

Setting up the JMenu

public JMenuBar setMenuBar()
        {
		JMenu file = new JMenu("File");
	
                difficulty = new JRadioButtonMenuItem[difLevel.length];
                for(int i = 0; i < difficulty.length; i++)
                {
                    difficulty[i] = new JRadioButtonMenuItem(difLevel[i]);
                    
                    file.add(difficulty[i]);
                    radioGroup.add(difficulty[i]);
                    // my problem is with the ItemHandler Handler);not sure how to set this up
                    difficulty[i].addActionListener(ItemHandler);
                }

Catching the ActionListener

private class ItemHandler implements ActionListener
        {
            public void actionPerformed(ActionEvent ae)
            {
               
		for( int i=0; i < difficulty.length; i++)
		{
			if(ae.getSource().equals("Easy"))
			{
				System.out.println("this is easy");
			}
                        else
                          if(ae.getSource().equals("Normal"))
			  {
			   	System.out.println("this is medium");
			  }
                        else
                          if(ae.getSource().equals("Hard"))
			  {
				System.out.println("this is hard");
			  }
               }
            }
        }

My problem is i'm getting this code not sure what to do with it. If anyone can point out where i'm going wrong, it would be a great help!!

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JRadioButtonMenuItem cannot be cast to javax.swing.JButton
toomuchfreetime 0 Light Poster

Thanks alot for that.

it's a great help spent last hour and a bit at it and i can see that it will work but can't figure out how to addActionListener(ItemHandler) to work.

not sure what way i'm mint to declare it. as i think this is the problem. is there a different Group for radio buttons?

ButtonGroup ItemHandler = new ButtonGroup();

This is the error message

C:\Documents and Settings\Stephen\My Documents\College\NetBeansProjects\hangManFromScrach\src\HangMan\HangMan.java:271: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (javax.swing.ButtonGroup)

Any idea about how to fix this problem

Thanks for your help

toomuchfreetime 0 Light Poster

Hey

I've been writing this hangman code for last week in college. and nearly got it finished but am after running into a problem. i want to run two different button handlers but can not figure out how to?.
one for the letter a to z which i have working but can not figure out how to get the RadioButton to work from the JMenu.Which i'll later use for setting the difficulty.
I'm new to the JMenu and more than one button grouping with an ActionListener so kind of confused.

I've attached my code so far and would appreasiate any help in pointing me in the right direction or tip or anything.

Thanks :

toomuchfreetime 0 Light Poster

Thanks
Anyway i just figured it out. Its alwas the way. wrecking my head for ages and once i post it i figure it out myself.

show = pickWord.replaceAll("[a-z]"," _ ");
toomuchfreetime 0 Light Poster

Hey
can any one help me i'm doing a hangman program and want to display blanks where a to z is. how can i do this?

I've got it replacing "a" but can't get it to replace the rest i.e. b to z

any help would be appriaciated.

show = pickWord.replaceAll("a"," _ ");
toomuchfreetime 0 Light Poster

thanks alot i shall try that this evening and let you know how i get on tomorrow.

and the reason i'm not using vectors is because we are not allowed. we have to make dynamic arrays using a series of pointers layed out in a function. and call this function once the array gets full and then double size of array or multiply by 1.5 or something.

toomuchfreetime 0 Light Poster

The following is a project that i'm working on at the moment and as i say is work in progress but having huge problem in trying to have a dynamicly re-sized array once the array gets too big.

in the programme which will mean i'll miss out in a huge amount of marks. i'm using const at moment but don't have clue how to do dynamic array:?:
it would be a great help if some one here could show me how to do this in my programme.

thanks alot if any one does


p.s. i know there are bugs in it i'll sort them out only need help with the setting up of dynamic arrays


cheers

toomuchfreetime 0 Light Poster

Sorry now but still not sure how to implement it into my programme:confused: rough example follows::::

#define MAX_PERSONS 100
 
 
struct array
{
    string name;
    
    int account; 
    
    double balance;
    
};
 
typedef  array ARRAY;   
 
 
ARRAY valu[MAX_PERSONS];
 
void add_account(ARRAY package_info[]);
 
 
int menu();
 
{
case 1 :   add_account(valu);
               break;
 
case 2 :   delete(valu);
               break;
 
case 3 :    amend(valu):
                break;
 
case 4 :    list(valu);
                break;
 
}

int menu();
{
 
BLA BLA BLA BLA
}
 
 
void add_account(ARRAY package_info[])
{
 
search array for freespace
 
   if no free space RESIZE
 
  else input data
 
 
}
toomuchfreetime 0 Light Poster

Hey everyone new to the board and in a bit of bother.

I've got this assignment thats been plaging me for two weeks but i can't do this one bit as i just don't get it.

I've got to write a programme that takes data in from a file and inserts them into arrays. the array is set up through a strut.

I should then be able to add,delete,amend,or list the data on the screen in certain orders.

now all this is O.K. i understand all this and can do this but i don't know how to dynamically resized an array if the array gets full ! :confused:
I've been scraching my head now for two weeks and nothing is going on will some one please take the time too explain how to implement this i would be very greatfull.:cheesy: :cheesy:

All those pointers get me confused PLUS not aloud to use VECTORS or old C malloc etc

thanks steve

p.s. great board