I want to write a Java program that reads the data from a file and stores it in an array. And then generates a random array index and uses it to retrieve a random word from the array to display. Each time the user clicks Next button, the program chooses a new random word to be displayed. I'm trying to add buttons in frame but they won't appear on the JFrame. Following is the code I wrote:
okButton = new JButton ("OK");
Pane.add(okButton);
nextButton = new JButton ("Next");
Pane.add(nextButton);
When the user enters a right answer I want a JLabel to appear saying " Correct answer ". How do I make a JLabel Appear? and when the user closes the frame all the right answers show in a JTextArea.
Can you please help me?
Your question is too much cluttered and vague to me, so providing perfect answer is quite not possible. Following are some useful tips you can use to solve your problem.
read file which contains the word. See File operations in Java and
How to use FileChooser?
Tokenize file and create an array of words. You can use StringTokenizer class for this
Create a method to randomly word from the array. You can use Random class for this.
For the GUI part:
the buttons won't appear on the JFrame
Are you adding panel containing buttons to frame properly?
how do I make a JLabel Appear ?
Add that JLabel to panel/frame and repaint it.
when the user closes the frame all the right answers show in a
JTextArea
Save right answers in some other array (call it answerArray).
Add Window listener to frame to monitor closing of frame.
In close method create a JDialog containing JTextArea and loop over answerArray and append string to textArea. Finally display this new JDialog.
Related
cantSee = collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true)
canSee = !(collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true))
Define the loop as the following:
if cantSee {
cantSeeTimer = cantSeeTimer +1
}
if cantSeeTimer >60 {
speed=0
stopped=true
} else {
mp_potential_step(obj_player.x,obj_player.y,5,false)
}
}
if stopped=true && canSee {
mp_potential_step(obj_player.x,obj_player.y,5,false)
loop()
}
I know the language is bad, but I just want to create a loop command to summon at will.
Thanks, Finn.
so you haven't specified which object in your game currently has this code but it shouldn't matter too much.
So in Game Maker or Game Maker Studio there are a series of events an object can have and one of them is called a "Step" event. A step event is basically a loop that will cycle the amount of times the room speed is per second. Eg: If the room speed of a room is 30 the step event will loop 30 times per second.
I think I can see what you are trying to do and I think I have a solution for you.
Since you can write GML code I am going to assume you understand how to use the GMS or GM IDE.
We want to create a new object called obj_control (or you can choose a custom name). Also don't give this object a sprite as we don't want the player to see it.
Now we want to add an event to our new object so make sure you still have the windows for obj_control (or whatever u called it open). and click on the 'Add Event button' shown in this image: http://imgur.com/A7szwFO
Once you click on it, click on 'Step'. http://imgur.com/s0ksiyD
Now select 'Step' again. ('Begin Step' and 'End Step' don't do what we want so let's just ignore them)
Now we need to add your code to the step event we just created. So make sure you are on the 'Control' tab and find the script editor (you should know where to find it) and drag one into the 'Actions' for the step event.
http://imgur.com/de3gE01
Now a script editor should pop up automatically but if it doesn't just double click the "Execute piece of code". Now we just need to copy and paste all of your code into the script editor.
http://imgur.com/sNBOCFu
Now click on the green tick on the top left corner of the window to save the code.
Now before we are done let's make sure we define the variables in a create event. So make a create event and add this code:
cantSee = collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true)
canSee = !(collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true))
After you have added that create event and inserted that code into it save all changes to the object.
All that is left is to add this object we created to every room of the game so it can function.
Hopefully this helped and if it didn't just let me know and we can get it sorted.
This question already has answers here:
Resizing an array at runtime in VB.NET
(8 answers)
Closed 8 years ago.
Okay so basically I need to create a grade book that allows the user to input their name, and the grades they received (say 5 test scores for example, some set amount).
It'll be inputted through a text box and displayed on a list box.
(And basically that's all it does.)
What I want to do now is, instead of overwriting the values each time when there's a new student, I want to store them inside an array.
Problem is, if I were do something like
Dim studentArray() As Integer
After an event, say a button click, it'll still overwrite it each time, once I click the button, right?
I was wondering if there was anyway around this?
My professor suggested that I use the inputted name as the array name, so that each time the button is clicked, the variable name would change so it won't constantly overwrite.
But I don't know how to do this.
Thank you in advance
EDIT: I was thinking about putting everything into a 2D array instead. Where the first column would be the names of the students followed by everything else? Would that be a good idea? (At the moment, we can assume the number of test is no more than 5, so a set amount is okay. Likewise for amount of students.)
you can use a Dictionary(Of string, integer()). And add the array to the dictionary. For example, to create the dictionary,
Dim dicStudentArrays As New Dictionay(Of String, Integer())
to add the array, being sName the inputted name
dicStudentArrays.Add(sName, studentArray)
to retrieve the array
studentArray = dicStudentArrays.Item(sName)
what I don't see is changing the name of a variable in the code while in execution
I have developed a graphic userinterface for a small program in c. Its some kind of calculator. I have two inputfields where one can enter numbers and I want to display the result as a text-label in the same window.
I do not know how to make the window or the text-label to update itself. I am used with GUIS in java and there are a method called invalidate() to refresh the window and its child-items? Is there a similar function in the gtk3-lib in c?
I don't understand. I think there is a button to press after entering numbers in inputfields, am i right? If so, just connect a function to the button clicked signal.
This function make the sum of 2 numbers and set the label text.
If you don't have the button, i think you need to connect the signal to the inputfields, something like:
"on_spinbutton1_value_changed" : update_text_label
P.S.
I don't know C, usally i use python, but i think is quite similar.
P.P.S.
Is this the same question founded here?
I am working on a flash project that dynamically generates navigation from an XML. For now I am trying to get it to work with arrays so that I can adapt it to xml once I know the logic works. I am new to as3 and learning has been a tiny bit bumpy. I have been searching for a solution to this but many of the examples I have seen have either been too simple to answer my question or too complex to understand since I am on the new side. This is the code I am working with.
var clientList:Array = new Array("Client1","Client2","Client3","Client4","Client5","Client6","Client7","Client8","Client9","Client10","Client11","Client12","Client13","Client14","Client15");
for each (var cName in clientList){
var newClientBtn:btnClientNav = new btnClientNav();
newClientBtn.x = workX;
newClientBtn.y = workY;
workY += newClientBtn.height;
newClientBtn.mcClientName.text = cName;
lContent.mcWork.addChild(newClientBtn.name);
trace(newClientBtn);
}
I can't fingure out how to properly refernce the dynamically created clips. I have a dynamic text box in the button but can't figure out how to reference it properly to change it, then my next issue will be referencing the buttons to make rollover and click code. I know this probably something simple to fix but I have been looking at it for too long and my eyes are starting to cross.. Thank you in advance for any advice you can give.
Why not store the clips you are creating in an object you can access later?
If you want to reference a movie clip by name though, one way to do it is:
var referenceMC:MovieClip = MovieClip(containerMC.getChildByName(“targetMC”));
If it was a text field or a button you were after, I believe you would do the same but instead cast the result of getChildByName to your desired control.
I also believe you want to add the button itself as a child, not pass its name into your addChild call?
I am creating printouts in WPF using flow documents. These printouts are set in separate window where DocumentViewer is placed.
When user clicks print I would like to show a progress bar that informs about current page that is sending to the printer. How can I do this?
I'm not sure exactly where your print code is, or where you want the progress bar, but I did something similar to this recently. This will be in VB.net.
First of all, create a new progressbar in the same class as the code you use to send the page to the printer. Then, we're going to take advantage of the "top-down" order in a block of code to change the progress bar.
The progress bar's value should be set to "0" be default. Now, in the code for sending the page to the printer, you're going to increase the progressbar's value (such as with the code "MyProgressBar.Value = MyProgressBar.Value + 1"). Put this code in between each line of the code you want to show progress for.
I would change the "+ 1" part of the code, however, to another value, so your progress bar progresses equally after each step. If you have three lines of code, then use "+ 33" (100\3), four lines use "+ 25", etc.
Finally, at the end of the code, set "MyProgressBar.Value = 100"
This only works, however, if you have access to a code longer than one line. For one line of code, I'm not sure how this works, unless you can get to the block of code that line points to.
If you have to use code from another class, you may need to do something like...
Dim MyWindowWhereProgressIs As New MyWindowWhereProgressIs
And then, each time you need to change the value, try...
MyWindowWhereProgressIs.MyProgressBar.Value = MyWindowWhereProgressIs.MyProgressBar.Value + 1
I'm not entirely sure whether or not those last two lines of code will work, as I'm away from Visual Studio right now, but it is worth a shot.