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 ;}
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 ;}
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
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
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.
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.
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
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: %
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
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
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 …
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.
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
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.
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; …
package NumberGame;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
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;
JScrollPane editorScrollPane;
MainPanel correction = new MainPanel();
ButtonHandler handler = new ButtonHandler();
MenuHandler ItemHandler = new MenuHandler();
player update = new player();
PicPanel change = new PicPanel();
private Icon life1 = new ImageIcon("willypoo2/1.gif");
private Icon life2 = new ImageIcon("willypoo2/2.gif");
private Icon life3 = new ImageIcon("willypoo2/3.gif");
private Icon life4 = new ImageIcon("willypoo2/4.gif");
private Icon life5 = new ImageIcon("willypoo2/5.gif");
private Icon life6 = new ImageIcon("willypoo2/6.gif");
private Icon life7 = new ImageIcon("willypoo2/7.gif");
private Icon life8 = new ImageIcon("willypoo2/8.gif");
private Icon life9 = new ImageIcon("willypoo2/9.gif");
private Icon life10 = new ImageIcon("willypoo2/10.gif");
NumberGame()
{
setMenuBar();
c = getContentPane();
c.setBackground(Color.WHITE);
setSize(300,300);
setLocation(250,100);
c.setVisible(true);
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);
help hfile = new help();
helppan = new JPanel();
helppan.setVisible(false);
helppan.add(hfile);
hideHelp = new JButton("Return");
hideHelp.addActionListener(ItemHandler);
helppan.add(hideHelp);
c.add(picpan,BorderLayout.NORTH);
c.add(mainpan,BorderLayout.CENTER);
c.add(playerpan,BorderLayout.SOUTH);
c.add(helppan,BorderLayout.EAST);
}
public class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
answeertotal = Integer.parseInt(answeer.getText( ));
if(answeertotal == total)
{
whichMessage = true;
messages();
picLevel++;
change.changePic();
correction.reset();
update.updateScore();
}
else
{
whichMessage = false;
messages();
update.updatelife();
answeer.setText("");
}
if(lives == 0)
{
JOptionPane.showMessageDialog(null, "Sorry Game is over Score is :" + scores, "", JOptionPane.INFORMATION_MESSAGE);
scores = 0;
lives += 5;
update.int2str();
correction.reset();
}
}
}
public class LanguageGroup implements ActionListener
{
public void actionPerformed(ActionEvent la)
{
for( int i=0; i < language.length; i++)
{
if(la.getSource() == language[i])
{
languageLevel = i;
correction.reset();
}
}
}
}
public class MenuHandler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
for( int i=0; i < difficulty.length; i++)
{
if(ae.getSource() == difficulty[i])
{
diffucultyLevel = i;
correction.reset();
}
}
if(ae.getSource() == help)
{
helppan.setVisible(true);
}
if(ae.getSource() == hideHelp)
{
helppan.setVisible(false);
}
}
}
public class help extends JPanel
{
help()
{
JEditorPane ch = createEditorPane();
editorScrollPane = new JScrollPane(ch);
editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
editorScrollPane.setPreferredSize(new Dimension(250, 145));
editorScrollPane.setMinimumSize(new Dimension(10, 10));
add(editorScrollPane);
}
private JEditorPane createEditorPane()
{
JEditorPane ch = new JEditorPane();
ch.setEditable(false);
java.net.URL helpURL = NumberGame.class.getResource("Help.html");
if (helpURL != null)
{
try {
ch.setPage(helpURL);
}
catch (IOException e)
{
System.err.println("Attempted to read a bad URL: " + helpURL);
}
}
else
{
System.err.println("Couldn't find file: Help.html");
}
return ch;
}
}
public class player extends JPanel
{
String lif,sco;
player()
{
int2str();
life = new JLabel(lif);
add(life);
score = new JLabel(sco);
add(score);
}
public void int2str()
{
if(languageLevel == 0)
{
lif = String.valueOf("Current lives : " + lives);
sco = String.valueOf("Current score : " + scores);
}
else
if(languageLevel == 1)
{
lif = String.valueOf("Current lives : " + lives);
sco = String.valueOf("Current score : " + scores);
}
else
{
lif = String.valueOf("der Momentanzustand : " + lives);
sco = String.valueOf("das laufende Satz : " + scores);
}
}
public void updateScore()
{
scores = scores + 10;
int2str();
score.setText(sco);
}
public void updatelife()
{
lives = lives - 1;
int2str();
life.setText(lif);
}
}
public class PicPanel extends JPanel
{
public PicPanel()
{
picture = new JLabel(createImageIcon("sun.jpg"));
add(picture);
}
public void changePic()
{
switch(picLevel)
{
case 0:
break;
case 1:
JOptionPane.showMessageDialog(null, "IN THE PIC with picLevel of : " + picLevel ,"",JOptionPane.ERROR_MESSAGE);
picture.setIcon(life1);
add(picture);
break;
case 2:
picture.setIcon(life2);
add(picture);
break;
case 3:
picture.setIcon(life3);
add(picture);
break;
case 4:
picture.setIcon(life4);
add(picture);
break;
case 5:
picture.setIcon(life5);
add(picture);
break;
case 6:
picture.setIcon(life6);
add(picture);
break;
case 7:
picture.setIcon(life7);
add(picture);
break;
case 8:
picture.setIcon(life8);
add(picture);
break;
case 9:
picture.setIcon(life9);
add(picture);
break;
case 10:
picture.setIcon(life10);
add(picture);
break;
}
}
protected ImageIcon createImageIcon(String path)
{
java.net.URL imgURL = NumberGame.class.getResource(path);
if (imgURL != null)
{
return new ImageIcon(imgURL);
}
else
{
System.err.println("Couldn't find file: " + path);
return null;
}
}
}
public class MainPanel extends JPanel
{
int num1,num2,num3,num4;
String join1,join2,join3,join4,prompt;
MainPanel()
{
random();
createsum();
sumQ = new JLabel(prompt);
add(sumQ);
answeer = new JTextField(10);
answeer.setEditable(true);
add(answeer);
compute();
answeer.addActionListener(handler);
}
public void random()
{
Random generator = new Random();
switch(diffucultyLevel)
{
case 0:
num1 = generator.nextInt(10) + 1;
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.
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.
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.
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 …
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 …
package NumberGame;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.awt.*;
import javax.swing.*;
import java.awt.*;
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 + 10;
int2str();
score.setText(sco);
}
public void updatelife()
{
lives = lives - 1;
int2str();
life.setText(lif);
}
}
class PicPanel extends JPanel
{
public PicPanel()
{
picture = new JLabel(createImageIcon("sun.jpg"));
add(picture);
}
protected ImageIcon createImageIcon(String path)
{
java.net.URL imgURL = NumberGame.class.getResource(path);
if (imgURL != null)
{
return new ImageIcon(imgURL);
}
else
{
System.err.println("Couldn't find file: " + path);
return null;
}
}
}
class MainPanel extends JPanel
{
int num1,num2;
String join1,join2,prompt;
MainPanel()
{
random();
createsum();
sumQ = new JLabel(prompt);
add(sumQ);
answeer = new JTextField(10);
answeer.setEditable(true);
add(answeer);
compute();
answeer.addActionListener(handler);
}
public void random()
{
Random generator = new Random();
num1 = generator.nextInt(99) + 1;
num2 = generator.nextInt(99) + 1;
join1 = String.valueOf(num1);
join2 = String.valueOf(num2);
}
public void createsum()
{
prompt = "The sum is : ";
prompt = prompt.concat(join1);
prompt = prompt.concat(" + ");
prompt = prompt.concat(join2);
}
public void compute()
{
total = num1 + num2;
}
public void reset()
{
random();
createsum();
sumQ.setText(prompt);
compute();
}
}
public static void main(String args[])
{
JFrame frame = new NumberGame();
frame.setVisible(true);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
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:$
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
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
package HangMan;
/**
*
* @author Stephen
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Random;
import javax.swing.JOptionPane;
public class HangMan extends JFrame
{
Container c;
JButton buttonSet[];
JTextField textField;
String display,pickWord,pickHint,show,choice;
JLabel label,wordlabel, hintlabel;
JPanel buttonPanel,labelPanel,picpanel, displaymenu;
JRadioButtonMenuItem easy,medium,hard;
char[] blank;
char[] displayWord;
int life = 7;
ButtonGroup ItemHandler = new ButtonGroup();
Icon life1 = new ImageIcon("stock.gif");
Icon life2 = new ImageIcon("head.gif");
Icon life3 = new ImageIcon("body.gif");
Icon life4 = new ImageIcon("1stArm.gif");
Icon life5 = new ImageIcon("2ndArm.gif");
Icon life6 = new ImageIcon("1stLeg.gif");
Icon life7 = new ImageIcon("2ndLeg.gif");
Icon life8 = new ImageIcon("Finish.gif");
Icon life9 = new ImageIcon("fireworks.jpg");
//test area
String[] difLevel ={"Easy", "Normal", "Hard"};
JRadioButtonMenuItem[] difficulty;
ButtonHandler handler = new ButtonHandler();
public HangMan()
{
setMenuBar();
c = getContentPane();
c.setBackground(Color.white);
setSize(200,200);
setLocation(250,100);
label = new JLabel();
label.setIcon(life1);
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setLayout(new BorderLayout());
label.setBackground(Color.magenta);
label.setPreferredSize(new Dimension(300,300));
picpanel = new JPanel();
picpanel.add(label);
picpanel.setVisible(true);
pickWord();
blankWord();
wordlabel = new JLabel(show);
wordlabel.setHorizontalAlignment(SwingConstants.CENTER);
wordlabel.setLayout(new BorderLayout());
wordlabel.setBackground(Color.CYAN);
wordlabel.setPreferredSize(new Dimension(300,40));
labelPanel = new JPanel();
labelPanel.add(wordlabel);
GridLayout lblayout = new GridLayout(0,1);
labelPanel.setLayout(lblayout);
textField = new JTextField();
textField.setHorizontalAlignment(JTextField.CENTER);
textField.setFont(new Font("Helvetica", Font.PLAIN, 20));
textField.setBackground(Color.blue);
textField.setPreferredSize(new Dimension(300,40));
labelPanel.add(textField);
hintlabel = new JLabel(pickHint);
hintlabel.setHorizontalAlignment(SwingConstants.CENTER);
hintlabel.setLayout(new BorderLayout());
hintlabel.setBackground(Color.yellow);
hintlabel.setPreferredSize(new Dimension(300,40));
labelPanel.add(hintlabel);
displayButtons();
c.add(picpanel,BorderLayout.NORTH);
c.add(labelPanel,BorderLayout.CENTER);
c.add(buttonPanel,BorderLayout.SOUTH);
display = new String();
}
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");
}
}
}
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton) e.getSource();
choice = button.getText();
if(life > 0)
{
if(e.getSource() == button)
{
display += button.getText();
textField.setText(display);
boolean isThere = false;
//check guess and compares to word. Replaces any correctly guessed letter
for (int start = 0; start < pickWord.length(); start++)
{
char[] check = choice.toCharArray();
if (check[0] == displayWord[start])
{
blank[start] = displayWord[start];
isThere = true;
}
}
show = new String(blank);
wordlabel.setText(show);
if (isThere != true)
{
life--;
}
setLives();
if(show.equals(pickWord))
{
JOptionPane.showMessageDialog(null, "WELL DONE!! YOU'VE DONE IT","",JOptionPane.INFORMATION_MESSAGE);
reset();
}
if (life < 1)
{
JOptionPane.showMessageDialog(null, "Sorry NO lives left","",JOptionPane.ERROR_MESSAGE);
reset();
}
}
}
else
{
JOptionPane.showMessageDialog(null, "Sorry NO lives left","",JOptionPane.ERROR_MESSAGE);
reset();
}
}
}
public void pickWord()
{
int look;
Random generator = new Random();
look = generator.nextInt(8) + 1;
pickWord = wordlibrary.WORD_LIST[look];
pickHint = wordlibrary.HINT_WORD_LIST[look];
}
public void blankWord()
{
displayWord = pickWord.toCharArray();
show = pickWord.replaceAll("[a-zA-Z0-9]","_");
blank = show.toCharArray();
}
public void setLives()
{
if(life == 7)
label.setIcon(life1);
if(life == 6)
label.setIcon(life2);
if(life == 5)
label.setIcon(life3);
if(life == 4)
label.setIcon(life4);
if(life == 3)
label.setIcon(life5);
if(life == 2)
label.setIcon(life6);
if(life == 1)
label.setIcon(life7);
if(life == 0)
label.setIcon(life8);
}
public void reset()
{
life = 7;
pickWord();
blankWord();
wordlabel.setText(show);
hintlabel.setText(pickHint);
display = "";
textField.setText("");
}
public void displayButtons()
{
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout( 4,3));
buttonSet = new JButton[26];
for (int i=65; i <= 90;i++)
{
buttonSet[i-65] = new JButton("" + ((char)i));
buttonPanel.add(buttonSet[i-65]);
buttonSet[i-65].addActionListener(handler);
buttonSet[i-65].setFont(new Font ("Helvetica",Font.BOLD, 18));
buttonSet[i-65].setForeground(Color.gray);
}
}
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]);
//also this adds the radio buttons to the file but does not group the radio
//buttons so that only on can be chosen. i.e.
//RadioButton = new ButtonGroup---PLACED OUTSIDE LOOP
//RadioButton.add(difficulty[i]);
file.add(difficulty[i]);
// my problem is with the ItemHandler Handler);not sure how to set this up
difficulty[i].addActionListener(ItemHandler);
}
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
bar.add(file);
return bar;
}
public static void main(String args[])
{
JFrame frame = new HangMan();
frame.setVisible(true);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
package HangMan;
/**
*
* @author Stephen
*/
/**
* Write a description of class WordLibrary here.
*
* @author (your name)
* @version (a version number or a date)
*/
public final class wordlibrary
{
protected static final String[] WORD_LIST = {
"MANCHESTER UNITED",
"GONE IN 60 SECONDS",
"CRASH",
"CHESS",
"NEED FOR SPEED",
"DAVID BECKHAM",
"DUBLIN",
"SYDNEY",
"TOKYO"
};
protected static final String[] HINT_WORD_LIST = {
"SPORT",
"FILM",
"FILM",
"SPORT",
"GAME",
"SPORTS PERSON",
"PLACE",
"PLACE",
"PLACE"
};
}
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 :
package HangMan;
/**
*
* @author Stephen
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Random;
import javax.swing.JOptionPane;
public class HangMan extends JFrame
{
Container c;
JButton buttonSet[];
JTextField textField;
String display,pickWord,pickHint,show,choice;
JLabel label,wordlabel, hintlabel;
JPanel buttonPanel,labelPanel,picpanel, displaymenu;
JRadioButtonMenuItem easy,medium,hard;
char[] blank;
char[] displayWord;
int life = 7;
ButtonGroup group = new ButtonGroup();
Icon life1 = new ImageIcon("stock.gif");
Icon life2 = new ImageIcon("head.gif");
Icon life3 = new ImageIcon("body.gif");
Icon life4 = new ImageIcon("1stArm.gif");
Icon life5 = new ImageIcon("2ndArm.gif");
Icon life6 = new ImageIcon("1stLeg.gif");
Icon life7 = new ImageIcon("2ndLeg.gif");
Icon life8 = new ImageIcon("Finish.gif");
//Icon life8 = new ImageIcon("fireworks.jpg");
ButtonHandler handler = new ButtonHandler();
public HangMan()
{
setMenuBar();
c = getContentPane();
c.setBackground(Color.white);
setSize(200,200);
setLocation(250,100);
label = new JLabel();
label.setIcon(life1);
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setLayout(new BorderLayout());
label.setBackground(Color.magenta);
label.setPreferredSize(new Dimension(300,300));
picpanel = new JPanel();
picpanel.add(label);
picpanel.setVisible(true);
pickWord();
blankWord();
wordlabel = new JLabel(show);
wordlabel.setHorizontalAlignment(SwingConstants.CENTER);
wordlabel.setLayout(new BorderLayout());
wordlabel.setBackground(Color.CYAN);
wordlabel.setPreferredSize(new Dimension(300,40));
labelPanel = new JPanel();
labelPanel.add(wordlabel);
GridLayout lblayout = new GridLayout(0,1);
labelPanel.setLayout(lblayout);
textField = new JTextField();
textField.setHorizontalAlignment(JTextField.CENTER);
textField.setFont(new Font("Helvetica", Font.PLAIN, 20));
textField.setBackground(Color.blue);
textField.setPreferredSize(new Dimension(300,40));
labelPanel.add(textField);
hintlabel = new JLabel(pickHint);
hintlabel.setHorizontalAlignment(SwingConstants.CENTER);
hintlabel.setLayout(new BorderLayout());
hintlabel.setBackground(Color.yellow);
hintlabel.setPreferredSize(new Dimension(300,40));
labelPanel.add(hintlabel);
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout( 4,3));
buttonSet = new JButton[26];
for (int i=65; i <= 90;i++)
{
buttonSet[i-65] = new JButton("" + ((char)i));
buttonPanel.add(buttonSet[i-65]);
buttonSet[i-65].addActionListener(handler);
buttonSet[i-65].setFont(new Font ("Helvetica",Font.BOLD, 18));
buttonSet[i-65].setForeground(Color.gray);
}
c.add(picpanel,BorderLayout.NORTH);
c.add(labelPanel,BorderLayout.CENTER);
c.add(buttonPanel,BorderLayout.SOUTH);
display = new String();
}
private class ButtonGroup implements ActionListener
{
public void itemStateChanged(ItemEvent e)
{
JRadioButton radio = (JRadioButton) (e.getSource());
if (radio.equals(medium))
{
reset();
}
}
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton) e.getSource();
choice = button.getText();
if(life > 0)
{
if(e.getSource() == button)
{
display += button.getText();
textField.setText(display);
boolean isThere = false;
//check guess and compares to word. Replaces any correctly guessed letter
for (int start = 0; start < pickWord.length(); start++)
{
char[] check = choice.toCharArray();
if (check[0] == displayWord[start])
{
blank[start] = displayWord[start];
isThere = true;
}
}
show = new String(blank);
wordlabel.setText(show);
if (isThere != true)
{
life--;
}
setLives();
if(show.equals(pickWord))
{
JOptionPane.showMessageDialog(null, "WELL DONE!! YOU'VE DONE IT","",JOptionPane.INFORMATION_MESSAGE);
reset();
}
if (life < 1)
{
JOptionPane.showMessageDialog(null, "Sorry NO lives left","",JOptionPane.ERROR_MESSAGE);
reset();
}
}
}
else
{
JOptionPane.showMessageDialog(null, "Sorry NO lives left","",JOptionPane.ERROR_MESSAGE);
reset();
}
}
}
public void pickWord()
{
// switch (JRadioButtonMenuItem)
// {
// case "easy":
/// break;
// case "medium":
// break;
// case "hard":
// break;
// }
int look;
Random generator = new Random();
look = generator.nextInt(8) + 1;
pickWord = wordlibrary.WORD_LIST[look];
pickHint = wordlibrary.HINT_WORD_LIST[look];
}
public void blankWord()
{
displayWord = pickWord.toCharArray();
show = pickWord.replaceAll("[a-zA-Z0-9]","_");
blank = show.toCharArray();
}
public void setLives()
{
if(life == 7)
label.setIcon(life1);
if(life == 6)
label.setIcon(life2);
if(life == 5)
label.setIcon(life3);
if(life == 4)
label.setIcon(life4);
if(life == 3)
label.setIcon(life5);
if(life == 2)
label.setIcon(life6);
if(life == 1)
label.setIcon(life7);
if(life == 0)
label.setIcon(life8);
}
public void reset()
{
life = 7;
pickWord();
blankWord();
wordlabel.setText(show);
hintlabel.setText(pickHint);
display = "";
textField.setText("");
}
public JMenuBar setMenuBar()
{
JMenu file = new JMenu("File");
//file.setMnemonic('F');
easy = new JRadioButtonMenuItem("Easy",true);
easy.isSelected();
easy.addActionListener(group);
//group.add(easy);
file.add(easy);
medium = new JRadioButtonMenuItem("Normal",false);
medium.addActionListener(group);
//group.add(medium);
file.add(medium);
hard = new JRadioButtonMenuItem("Hard",false);
hard.addActionListener(group);
// group.add(hard);
file.add(hard);
file.addSeparator();
JMenuItem exitItem = new JMenuItem("Exit");
file.add(exitItem);
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
bar.add(file);
return bar;
}
public static void main(String args[])
{
JFrame frame = new HangMan();
frame.setVisible(true);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
package HangMan;
/**
*
* @author Stephen
*/
/**
* Write a description of class WordLibrary here.
*
* @author (your name)
* @version (a version number or a date)
*/
public final class wordlibrary
{
protected static final String[] WORD_LIST = {
"MANCHESTER UNITED",
"GONE IN 60 SECONDS",
"CRASH",
"CHESS",
"NEED FOR SPEED",
"DAVID BECKHAM",
"DUBLIN",
"SYDNEY",
"TOKYO"
};
protected static final String[] HINT_WORD_LIST = {
"SPORT",
"FILM",
"FILM",
"SPORT",
"GAME",
"SPORTS PERSON",
"PLACE",
"PLACE",
"PLACE"
};
}
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]"," _ ");
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"," _ ");
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.
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
#include <iostream>
#include <iomanip>
#include<string>
#include <fstream>
#include <stdio.h>
using namespace std;
//#define MAX_PERSONS 100
const int size = 30;
struct bsupplyer
{
string name, type ,hourlylimit;
int mbs, contention, downloadlimit, contactnum ;
double connectionfee, excesscharge , cost;
};
typedef bsupplyer BSUPPLYER;
string name1, type1 ,hourlylimit1;
int mbs1, contention1, downloadlimit1, contactnum1 ,choice;
double connectionfee1, excesscharge1 , cost1;
void load_package(BSUPPLYER package_info[]) ;
void list_package(BSUPPLYER package_info[]);
void add_package(BSUPPLYER package_info[]);
void delete_package(BSUPPLYER package_info[]);
int menu();
BSUPPLYER supply[size];
int main()
{
system("mode con cols=130 lines=30");
system("color 2a");
while(choice != 5)
{choice = menu();
load_package( supply) ;
switch ( choice)
{
case 1 : system ( " cls " );
add_package(supply);
break;
case 2 : system ( " cls " );
delete_package(supply);
break;
case 3 : system ( " cls " );
break;
case 4 : system ( " cls " );
list_package( supply) ;
break;
case 5 :
return 0;
break;
}
}
}
void load_package(BSUPPLYER package_info[])
{
ifstream data("packages.txt", ios::in);
data.seekg(0);
for(int i = 0; !data.eof(); i++)
{
data>>package_info[i].name>>package_info[i].type>>package_info[i].mbs>>package_info[i].hourlylimit
>>package_info[i].contention>>package_info[i].downloadlimit>>package_info[i].connectionfee
>>package_info[i].excesscharge>>package_info[i].contactnum>>package_info[i].cost;
}
}
int menu()
{ int c;
system("CLS");
cout << endl << endl << endl << endl ;
cout << setw (65) << " Welcome to callcosts.ie " << endl;
cout <<endl << setw (40) << " 1 : Add packages details " << endl<<endl;
cout << setw (40) << " 2 : Delete package details " << endl<<endl;
cout << setw (40) << " 3 : amend details on a package" << endl<<endl;
cout << setw (40) << " 4 : List packages " << endl<<endl;
cout << setw (40) << " 5: Quit " << endl;
cout << endl << endl << endl << setw (40) << " Please enter choice : ";
cin >> c;
return c;
}
void list_package(BSUPPLYER package_info[])
{
for( int i =0; package_info[i].mbs != 0; i++)
{
cout<<package_info[i].name <<" "<<package_info[i].type<<" "<<package_info[i].mbs<<" "
<<package_info[i].hourlylimit<<" "<<package_info[i].contention<<" "<<package_info[i].downloadlimit
<<" "<<package_info[i].connectionfee<<" "<<package_info[i].excesscharge<<" "<<package_info[i].contactnum<<" "
<<package_info[i].cost<<endl;
}
system("pause");
}
void add_package(BSUPPLYER package_info[])
{
int i =0;
while ( package_info[i].mbs != 0 && i < size)
i++;
if ( i == size )
cout << "\nsorry, the database is full\n" ;
else
{
cout << "\nPlease enter broadband provider : ";
cin >> package_info[i].name ;
cout << "Please enter type of service e.g. wireless/dsl: " ;
cin >> package_info[i].type;
cout << " Broadband speed :" ;
cin >> package_info[i].mbs ;
cout << " Hourly limit ? " ;
cin >> package_info[i].hourlylimit;
cout << " contention ratio ?" ;
cin >> package_info[i].contention;
cout << "Download limit ";
cin >> package_info[i].downloadlimit ;
cout << "what is the connection fee" ;
cin >> package_info[i].connectionfee ;
cout << " what is the excess charge for going over the limit " ;
cin >> package_info[i].excesscharge;
cout << " what is the contact number" ;
cin >> package_info[i].contactnum ;
cout << " total cost of broadband package" ;
cin >> package_info[i].cost ;
}
ofstream data("packages.txt", ios::out);
for( int i =0; package_info[i].mbs != 0 ; i++)
{
data<<" "<<package_info[i].name<<" "<<package_info[i].type<<" "<<package_info[i].mbs
<<" "<<package_info[i].hourlylimit<<" "<<package_info[i].contention<<" "<<package_info[i].downloadlimit<<" "
<<package_info[i].connectionfee<<" "<<package_info[i].excesscharge<<" "<<package_info[i].contactnum<<" "<<package_info[i].cost
<<endl;
}
}
void delete_package(BSUPPLYER package_info[])
{
char decision;
int limit = 10;
int i =0;
while ( decision != 'Y' )
{
system("CLS");
while( i < limit && package_info[i].mbs != 0 )
{
cout<<package_info[i].name <<" "<<package_info[i].type<<" "<<package_info[i].mbs<<" "
<<package_info[i].hourlylimit<<" "<<package_info[i].contention<<" "<<package_info[i].downloadlimit
<<" "<<package_info[i].connectionfee<<" "<<package_info[i].excesscharge<<" "<<package_info[i].contactnum<<" "
<<package_info[i].cost<<endl;
i++;
}
limit = limit + 10;
cout << " Is the package you want to delete on the screen y/n or e to exit ";
cin >> decision;
decision = toupper(decision);
if ( package_info[i].mbs != 0 )
{
break;
}
}
int reset = -1;
cout << " Please enter the package details that you want deleted " << endl;
cin >> name1 >> type1 >> mbs1 >> hourlylimit1 >> contention1 >> downloadlimit1
>> connectionfee1 >> excesscharge1 >>contactnum1 >> cost1;
while( ! cin )
{
cin.clear();
cin.ignore(80,'\n');
cout << " Please enter the package details that you want deleted " << endl;
cin >> name1 >> type1 >> mbs1 >> hourlylimit1 >> contention1 >> downloadlimit1
>> connectionfee1 >> excesscharge1 >>contactnum1 >> cost1;
}
for ( int f =0; package_info[f].mbs != 0;f++)
{
if ( package_info[f].name == name1, package_info[f].type == type1, package_info[f].mbs == mbs1, package_info[f].hourlylimit == hourlylimit1,
package_info[f].contention == contention1, package_info[f].downloadlimit == downloadlimit1, package_info[f].connectionfee == connectionfee1,
package_info[f].excesscharge == excesscharge1, package_info[f].contactnum == contactnum1,package_info[f].cost == cost1)
{
package_info[f].name = reset, package_info[f].type = reset, package_info[f].mbs = reset, package_info[f].hourlylimit = reset,
package_info[f].contention = reset, package_info[f].downloadlimit = reset, package_info[f].connectionfee = reset, package_info[f].excesscharge = reset,
package_info[f].contactnum = reset,package_info[f].cost = reset;
}
else
{
cout << " You have entered the wrong package details " ;
break;
}
}
ofstream data("packages.txt");
for( int i =0; package_info[i].mbs != 0; i++)
{
data<<package_info[i].name<<" "<<package_info[i].type<<" "<<package_info[i].mbs<<" "
<<package_info[i].hourlylimit<<" "<<package_info[i].contention<<" "<<package_info[i].downloadlimit<<" "
<<package_info[i].connectionfee<<" "<<package_info[i].excesscharge<<" "<<package_info[i].contactnum<<" "<<package_info[i].cost<<endl;
}
system("pause");
}
churus dsl 3 40 30 40 99 5 2642412 20
perlico dsl 3 33 30 40 99 5 2642412 20
churus wireless 3 33 30 40 99 5 2342412 20
ntl dsl 3 33 30 40 99 5 2642812 20
btireland wireless 1 80 35 20 49 10 3434343 23
sky wireless 5 yes 30 40 99 5 2642032 23
ntl dsl 5 yes 30 40 99 5 2645032 24
smart dsl 1 yes 30 80 110 0 3747376 25
perlico dsl 1 2 3 4 5 6 67676 28
ntl wireless 4 22 30 40 99 5 2642912 30
eircom wireless 1 2 3 4 5 6 57485 31
perlico wireless 1 2 3 4 5 6 7654456 33
eircom dsl 1 2 3 4 5 6 67676 34
eircom dsl 1 yes 3 6 5 6 4343 37
smart dsl 1 2 3 4 5 6 4343 37
smart dsl 4 yes 30 50 90 5 8765755 40
smart dsl 9 8 7 6 5 4 3545 42
magnet wireless 5 22 30 40 99 5 2642834 46
magnet wireless 3 22 30 40 99 5 2642834 46
ntl dsl 5 22 30 40 99 5 2642834 46
churus wireless 3 33 30 40 99 5 2642812 50
eircom dsl 1 20 30 50 99 10 2647012 50
magnet dsl 4 22 30 40 99 5 2642912 51
eircom dsl 4 22 30 40 99 5 2642912 51
eircom dsl 6 30 30 40 99 5 2642012 52
ntl dsl 1 2 3 4 5 6 55555 55
magnet dsl 6 yes 20 50 200 5 8675858 59
steve dsl 3 2 3 4 5 6 7 6
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
}
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