Stuck on a simple program!!!
Hello everyone!
I've recently started C# programming, and we have been given an assignment to complete for 2 weeks time - it's like a trivia game, using different question types. I've started doing it, but even though the code looks correct, I have some major problems,
and I just don't know what's wrong. The said problems are:
1)The Stream Reader does not read my username or score, and these do not appear in the text file
2)The Current Score and High Scores do not appear in the textboxes, they're supposed to
3)I programmed the score to appear next to a label, when the Submit button is clicked, but when I do so, the label is replaced by the score, and I wanted it to appear next to it.
4)When I try to drag and drop three images, they won't budge and show a "forbidden" sign
5)My question buttons in the Main Form aren't becoming Read-Only, even though I
Here's the code for the Main Form (my main menu)
namespace GermanQuiz
public partial class frmMain : Form
//This creates a thread which executes the SplashStart method, which then opens the SplashScreen form.
//The form will then run for 5 seconds to let the progress bar load - after 5 seconds the Splash Screen will close
//then the Main Form will open. The thread is then terminated and afterwards closed.
public frmMain()
Thread t = new Thread(new ThreadStart(SplashStart));
t.Start();
Thread.Sleep(5000);
InitializeComponent();
t.Abort();
//This loads and then runs the User Login Form
Application.Run(new UserLogin());
//This opens and runs the Main Form
InitializeComponent();
//This displays the entered name of the new user and their current score
txtCurrentPlayerName.Text = CurrentPlayer.CurrentPlayerName;
txtCurrentPlayerScoreValue.Text = CurrentPlayer.CurrentPlayerScore.ToString();
//This removes all past text box contents
txtCurrentPlayerName.TabStop = false;
txtCurrentPlayerScoreValue.TabStop = false;
txtHighScoreName.TabStop = false;
txtHighScoreValue.TabStop = false;
public void SplashStart()
Application.Run(new frmSplashScreen());
//This reads the HighScore.txt file line by line and retrieves the first and second lines and assigns them as
//the HighScoreName and HighScoreValue variables.
//The line requested is returned to where the method was called.
public string ReadLine(string FilePath, int LineNumber)
string result = "";
try
if (File.Exists(FilePath))
using (StreamReader _StreamReader = new StreamReader(FilePath))
for (int a = 0; a < LineNumber; a++)
result = _StreamReader.ReadLine();
catch
//if the file doesn't exist, the catch handles the exception
MessageBox.Show("Can't find the High Score text file!", "Can't open file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
return result;
private void frmMain_Load(object sender, EventArgs e)
//The ReadLine method is executed - the path of the text file to be read and the line to be returned are passed as a parameter.
// ../../../ is used to go back throught three of the folders to retrieve the text file
string HighScoreName = ReadLine(@"../../HighScore.txt", 1);
txtHighScoreName.Text = HighScoreName;
//This assigns the Highscore Name to the global high score name variable in the HighScorePlayer Class
HighScorePlayer.HighScorePlayerName = HighScoreName;
//the ReadLine method executed - the path of the text file to be read and the line to be returned are passed as a parameter.
string line2 = ReadLine(@"../../HighScore.txt", 2);
Int16 HighScoreValue = Int16.Parse(line2);
txtHighScoreValue.Text = HighScoreValue.ToString();
HighScorePlayer.HighScorePlayerScore = HighScoreValue;
//On-click of this button, the form for Question 1 will open.
//Then the button for Question 1 will become Read-Only
private void btnQ1_Click_1(object sender, EventArgs e)
//This instantiates a new Form
Form myQuestion1 = new frmQuestion1();
//This shows the form
myQuestion1.Show();
btnQ1.Enabled = false;
//On-click of this button, the form for Question 2 will open.
//Then the button for Question 2 will become Read-Only
private void btnQ2_Click(object sender, EventArgs e)
//This instantiates a new Form
Form myQuestion2 = new frmQuestion2();
//This shows the form
myQuestion2.Show();
btnQ2.Enabled = false;
//On-click of this button, the form for Question 3 will open.
//Then the button for Question 3 will become Read-Only
private void btnQ3_Click(object sender, EventArgs e)
//This instantiates a new Form
Form myQuestion3 = new frmQuestion3();
//This shows the form
myQuestion3.Show();
btnQ3.Enabled = false;
//On-click of this button, the form for Question 4 will open.
//Then the button for Question 4 will become Read-Only
private void btnQ4_Click(object sender, EventArgs e)
//This instantiates a new Form
Form myQuestion4 = new frmQuestion4();
//This shows the form
myQuestion4.Show();
btnQ4.Enabled = false;
//On-click of this button, the form for Question 5 will open.
//Then the button for Question 5 will become Read-Only
private void btnQ5_Click(object sender, EventArgs e)
//This instantiates a new Form
Form myQuestion5 = new frmQuestion5();
//This shows the form
myQuestion5.Show();
btnQ5.Enabled = false;
//On-click of this button, the form for Question 6 will open.
//Then the button for Question 6 will become Read-Only
private void btnQ6_Click(object sender, EventArgs e)
//This instantiates a new Form
Form myQuestion6 = new frmQuestion6();
myQuestion6.Show();
btnQ6.Enabled = false;
//When the form is opened again after a past game, then the current score textbox is updated
protected override void OnActivated(EventArgs e)
txtCurrentPlayerScoreValue.Text = CurrentPlayer.CurrentPlayerScore.ToString();
base.OnActivated(e);
//If the player has beaten the highscore, then a message will appear, notifying that.
private void btnClose_Click(object sender, EventArgs e)
if (MessageBox.Show("Are you sure you wish to exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (CurrentPlayer.CurrentPlayerScore > HighScorePlayer.HighScorePlayerScore)
MessageBox.Show("Congratulations, you have beaten the high score!", "Well Done!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
string filePath = "../../HighScore.txt";
string[] fileLinesToBeWritten = { CurrentPlayer.CurrentPlayerName, CurrentPlayer.CurrentPlayerScore.ToString() };
File.WriteAllLines(filePath, fileLinesToBeWritten);
Application.Exit();
else
MessageBox.Show("Looks like your score hasn't improved,\nBetter luck next time!", "Ah well!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
Application.Exit();
//On-click of this exit button, the program is closed
private void btnExit_Click(object sender, EventArgs e)
Application.Exit();
Then my code for that pesky label:
lblScore.Text = calculateScore.ToString();
And for the drag and drop question:
namespace GermanQuiz
public partial class frmQuestion2 : Form
public frmQuestion2()
InitializeComponent();
//This enables "Allow Drop" to drag and drop pictures held in the pictureboxes.
private void frmQuestion2_Load(object sender, EventArgs e)
pictureBox1.AllowDrop = true;
pictureBox2.AllowDrop = true;
pictureBox3.AllowDrop = true;
pictureBox4.AllowDrop = true;
pictureBox5.AllowDrop = true;
pictureBox6.AllowDrop = true;
//This creates two variables: one to hold the picturebox tag (selectedPicture) and one
//to hold the correct picture score.
public static String selectedPicture;
public static int calculateScore;
//On click of the button, this creates an event (MouseDown) on the picture on the left and then a copy of the picture to drop on the right is made.
//Also the picture tag to a temporary string variable (selectedPicture) is copied to use later. "On Drop" to see the if correct picture was
//selected.
//First for Picture Box 1
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
selectedPicture = pictureBox1.Tag.ToString();
pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
//Then for Picture Box 2
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
selectedPicture = pictureBox2.Tag.ToString();
pictureBox2.DoDragDrop(pictureBox2.Image, DragDropEffects.Copy);
//And finally for Picture Box 3
private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
selectedPicture = pictureBox3.Tag.ToString();
pictureBox3.DoDragDrop(pictureBox3.Image, DragDropEffects.Copy);
//Pictures dropped on the right hand side will be copied to the pictureBox.
//Also "Allow Drop" the picture that is dropped to finalise the selection.
//First for Picture Box 4
private void pictureBoxA_DragDrop(object sender, DragEventArgs e)
pictureBox4.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
pictureBox4.AllowDrop = false;
if (selectedPicture == pictureBox4.Tag.ToString())
calculateScore += 1;
private void pictureBoxA_DragEnter(object sender, DragEventArgs e)
e.Effect = DragDropEffects.Copy;
//Then for Picture Box 5
private void pictureBoxB_DragDrop(object sender, DragEventArgs e)
pictureBox5.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
pictureBox5.AllowDrop = false;
if (selectedPicture == pictureBox5.Tag.ToString())
calculateScore += 1;
private void pictureBoxB_DragEnter(object sender, DragEventArgs e)
e.Effect = DragDropEffects.Copy;
//And finally for Picture Box 6
private void pictureBoxC_DragDrop(object sender, DragEventArgs e)
pictureBox6.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
pictureBox6.AllowDrop = false;
if (selectedPicture == pictureBox6.Tag.ToString())
calculateScore += 1;
private void pictureBoxC_DragEnter(object sender, DragEventArgs e)
e.Effect = DragDropEffects.Copy;
//This makes the submit button Read-Only, then it calculates
//the scores from your answers, and sums them to the total score.
private void btnSubmit2_Click(object sender, EventArgs e)
btnSubmit2.Enabled = false;
lblScore.Text = calculateScore.ToString();
CurrentPlayer.CurrentPlayerScore += calculateScore;
//This closes the form once the "Exit" button is clicked
private void btnExit2_Click(object sender, EventArgs e)
this.Close();
My Currentplayer/Highscore classes:
namespace GermanQuiz
class CurrentPlayer
public static String CurrentPlayerName;
public static int CurrentPlayerScore;
namespace GermanQuiz
class HighScorePlayer
public static String HighScorePlayerName;
public static Int16 HighScorePlayerScore;
I just don't see what's wrong. Can you please Help me!
Try changing the streamreader to code below
//This reads the HighScore.txt file line by line and retrieves the first and second lines and assigns them as
//the HighScoreName and HighScoreValue variables.
//The line requested is returned to where the method was called.
StreamReader _StreamReader = null;
public string ReadLine(string FilePath)
if(_StreamReader == null)
if (File.Exists(FilePath))
_StreamReader = new StreamReader(FilePath);
string result = "";
try
if(_StreamReader != null)
using (_StreamReader)
result = _StreamReader.ReadLine();
catch
//if the file doesn't exist, the catch handles the exception
MessageBox.Show("Can't find the High Score text file!", "Can't open file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
return result;
jdweng
Similar Messages
-
Need help with a simple program (should be simple anyway)
I'm (starting to begin) writing a nice simple program that should be easy however I'm stuck on how to make the "New" button in the file menu clear all the fields. Any help? I'll attach the code below.
====================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Message extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent evt) {
text1.setText(" ");
text2.setText("RE: ");
text3.setText(" ");
public Message() {
super("Write a Message - by Kieran Hannigan");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(370,270);
FlowLayout flo = new FlowLayout(FlowLayout.RIGHT);
setLayout(flo);
//Make the bar
JMenuBar bar = new JMenuBar();
//Make "File" on Menu
JMenu File = new JMenu("File");
JMenuItem f1 = new JMenuItem("New");f1.addActionListener(this);
JMenuItem f2 = new JMenuItem("Open");
JMenuItem f3 = new JMenuItem("Save");
JMenuItem f4 = new JMenuItem("Save As");
JMenuItem f5 = new JMenuItem("Exit");
File.add(f1);
File.add(f2);
File.add(f3);
File.add(f4);
File.add(f5);
bar.add(File);
//Make "Edit" on menu
JMenu Edit = new JMenu("Edit");
JMenuItem e1 = new JMenuItem("Cut");
JMenuItem e2 = new JMenuItem("Paste");
JMenuItem e3 = new JMenuItem("Copy");
JMenuItem e4 = new JMenuItem("Repeat");
JMenuItem e5 = new JMenuItem("Undo");
Edit.add(e5);
Edit.add(e4);
Edit.add(e1);
Edit.add(e3);
Edit.add(e2);
bar.add(Edit);
//Make "View" on menu
JMenu View = new JMenu("View");
JMenuItem v1 = new JMenuItem("Bold");
JMenuItem v2 = new JMenuItem("Italic");
JMenuItem v3 = new JMenuItem("Normal");
JMenuItem v4 = new JMenuItem("Bold-Italic");
View.add(v1);
View.add(v2);
View.add(v3);
View.addSeparator();
View.add(v4);
bar.add(View);
//Make "Help" on menu
JMenu Help = new JMenu("Help");
JMenuItem h1 = new JMenuItem("Help Online");
JMenuItem h2 = new JMenuItem("E-mail Programmer");
Help.add(h1);
Help.add(h2);
bar.add(Help);
setJMenuBar(bar);
//Make Contents of window.
//Make "Subject" text field
JPanel row2 = new JPanel();
JLabel sublabel = new JLabel("Subject:");
row2.add(sublabel);
JTextField text2 = new JTextField("RE:",24);
row2.add(text2);
//Make "To" text field
JPanel row1 = new JPanel();
JLabel tolabel = new JLabel("To:");
row1.add(tolabel);
JTextField text1 = new JTextField(24);
row1.add(text1);
//Make "Message" text area
JPanel row3 = new JPanel();
JLabel Meslabel = new JLabel("Message:");
row3.add(Meslabel);
JTextArea text3 = new JTextArea(6,22);
messagearea.setLineWrap(true);
messagearea.setWrapStyleWord(true);
JScrollPane scroll = new JScrollPane(text3,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//SpaceLine
JPanel spaceline = new JPanel();
JLabel spacer = new JLabel(" ");
spaceline.add(spacer);
row3.add(scroll);
add(row1);
add(row2);
add(spaceline);
add(spaceline);
add(row3);
setVisible(true);
public static void main(String[] arguments) {
Message Message = new Message();
}persiandude wrote:
Topic: Need help with if, else, and which statements and loops.
How would I display 60 < temp. <= 85 in java
System.out.println("60 < temp. <= 85 in java");
another question is how do I ask a question like want to try again (y/n) after a output and asking that everytime I type in yes after a output and terminate when saying No.Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
[http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]. -
Ideas For a Simple Program?
I need some ideas for a simple program for a project in class. Can anyone help me?
Import Classes
import java.io.*;
public class tictactoe
Define Variables
public static InputStreamReader ISR = new InputStreamReader(System.in);
public static BufferedReader BFR = new BufferedReader(ISR);
public static String BOX[][] = new String[3][3]; //Integer Arry for tictactoe box
public static String PName; //Moving Player's Name
public static String P1Name; //Player 1 Name
public static String P2Name; //Player 2 Name
public static String InputPLY; //X or O
public static String InputStr; //Player's Input
public static boolean BreakLoop; //Set this to true in PlayGame() to exit
public static void main(String args[]) throws IOException
InputPLY = "O";
BreakLoop = false;
ClearBOXCache();
PrintCredits();
System.out.println("");
System.out.println("PLEASE ENTER PLAYER 1 NAME");
P1Name = BFR.readLine();
System.out.println("PLEASE ENTER PLAYER 2 NAME");
P2Name = BFR.readLine();
System.out.println("");
System.out.print("\nWelcome ");
System.out.print(P1Name);
System.out.print(" and ");
System.out.println(P2Name);
System.out.println("");
System.out.println(P1Name + " = X");
System.out.println(P2Name + " = O");
PlayGame();
PrintCredits();
BFR.readLine();
System.exit(0);
public static void DrawGrid()
This function is to draw the tictactoe grid.
System.out.println("");
System.out.println("\t/-----------------------------\\");
System.out.println("\t|-------- TIC TAC TOE --------|");
System.out.println("\t|-----------------------------|");
System.out.println("\t| | | |");
System.out.println("\t| " + BOX[0][0] + " | " + BOX[0][1] + " | " + BOX[0][2] + " |");
System.out.println("\t| | | |");
System.out.println("\t|-----------------------------|");
System.out.println("\t| | | |");
System.out.println("\t| " + BOX[1][0] + " | " + BOX[1][1] + " | " + BOX[1][2] + " |");
System.out.println("\t| | | |");
System.out.println("\t|-----------------------------|");
System.out.println("\t| | | |");
System.out.println("\t| " + BOX[2][0] + " | " + BOX[2][1] + " | " + BOX[2][2] + " |");
System.out.println("\t| | | |");
System.out.println("\t\\-----------------------------/");
public static void PrintCredits()
This function is to print credits. Intended for startup and ending
System.out.println("");
System.out.println("");
System.out.println("\t-------------------------------");
System.out.println("\t--------- TIC TAC TOE ---------");
System.out.println("\t-------------------------------");
System.out.println("");
System.out.println("\t-------------------------------");
System.out.println("\t---- MADE BY WILLIAM CHAN! ----");
System.out.println("\t-------------------------------");
public static void ClearBOXCache()
This function is to clear the BOX's cache.
It is intended for restarting a game
BOX[0][0] = " ";
BOX[0][1] = " ";
BOX[0][2] = " ";
BOX[1][0] = " ";
BOX[1][1] = " ";
BOX[1][2] = " ";
BOX[2][0] = " ";
BOX[2][1] = " ";
BOX[2][2] = " ";
public static void CheckWin(String PLYW) throws IOException
This function is to check if a player wins
for (int X = 0; X < 3; X++)
if (BOX[X][0].equals(PLYW) && BOX[X][1].equals(PLYW) && BOX[X][2].equals(PLYW))
PrintWin(PLYW);
for (int Y = 0; Y < 3; Y++)
if (BOX[0][Y].equals(PLYW) && BOX[1][Y].equals(PLYW) && BOX[2][Y].equals(PLYW))
PrintWin(PLYW);
if (BOX[0][0].equals(PLYW) && BOX[1][1].equals(PLYW) && BOX[2][2].equals(PLYW))
PrintWin(PLYW);
else if (BOX[0][2].equals(PLYW) && BOX[1][1].equals(PLYW) && BOX[2][0].equals(PLYW))
PrintWin(PLYW);
else if (!BOX[0][0].equals(" ") && !BOX[0][1].equals(" ") && !BOX[0][2].equals(" ") && !BOX[1][0].equals(" ") && !BOX[1][1].equals(" ") && !BOX[1][2].equals(" ") && !BOX[2][0].equals(" ") && !BOX[2][1].equals(" ") && !BOX[2][2].equals(" "))
ClearBOXCache();
System.out.println("Tie Game!");
BFR.readLine();
System.out.println("Game has restarted");
public static void PrintWin(String PrintWinner) throws IOException
This function is to print which player won
if (PrintWinner.equals("X"))
System.out.println(P1Name + " wins!");
System.out.println(P2Name + " loses!");
else if (PrintWinner.equals("O"))
System.out.println(P2Name + " wins!");
System.out.println(P1Name + " loses!");
BFR.readLine();
ClearBOXCache();
System.out.println("Game has restarted!");
public static void PrintInstruction(String PLYINSTR)
This function is to give instruction to the player
if (PLYINSTR.equals("X"))
PName = (P1Name);
else if (PLYINSTR.equals("O"))
PName = (P2Name);
System.out.println("");
System.out.println(PName + ":");
System.out.println("PLEASE MAKE YOUR MOVE");
System.out.println("");
System.out.println("TL = TOP LEFT BOX, TM = TOP MIDDLE BOX, TR = TOP RIGHT BOX");
System.out.println("ML = MIDDLE LEFT BOX, MM = MIDDLE MIDDLE BOX, MR = MIDDLE RIGHT BOX");
System.out.println("BL = BOTTOM LEFT BOX, BM = BOTTOM MIDDLE BOX, BR = BOTTOM RIGHT BOX");
public static void PlayGame() throws IOException
This function is the main game function.
It calls other game functions.
Define Variables
while(true)
if (InputPLY.equals("O"))
InputPLY = "X";
else if (InputPLY.equals("X"))
InputPLY = "O";
while(true)
PrintInstruction(InputPLY);
InputStr = BFR.readLine(); //Player's move
Check player's move
if (InputStr.equals("TL"))
if (BOX[0][0].equals(" "))
BOX[0][0] = InputPLY;
break;
else if (InputStr.equals("TM"))
if (BOX[0][1].equals(" "))
BOX[0][1] = InputPLY;
break;
else if (InputStr.equals("TR"))
if (BOX[0][2].equals(" "))
BOX[0][2] = InputPLY;
break;
else if (InputStr.equals("ML"))
if (BOX[1][0].equals(" "))
BOX[1][0] = InputPLY;
break;
else if (InputStr.equals("MM"))
if (BOX[1][1].equals(" "))
BOX[1][1] = InputPLY;
break;
else if (InputStr.equals("MR"))
if (BOX[1][2].equals(" "))
BOX[1][2] = InputPLY;
break;
else if (InputStr.equals("BL"))
if (BOX[2][0].equals(" "))
BOX[2][0] = InputPLY;
break;
else if (InputStr.equals("BM"))
if (BOX[2][1].equals(" "))
BOX[2][1] = InputPLY;
break;
else if (InputStr.equals("BR"))
if (BOX[2][2].equals(" "))
BOX[2][2] = InputPLY;
break;
else if (InputStr.equals("RESTART"))
ClearBOXCache();
System.out.println("");
System.out.println("GAME RESTARTED!");
System.out.println("");
break;
else if (InputStr.equals("QUIT"))
BreakLoop = true;
break;
if (BreakLoop == true)
break;
DrawGrid();
CheckWin(InputPLY);
} -
Any ideas for a (fairly) simple program?
Does anybody have any ideas for a fairly simple program that I could try to write (I am a fair programmer, but I'm not to creative)?
You know, Java Game Programming for Dummies is actually a pretty good book (despite the "Dummies" part!) It is written in 1.0, but it has a "ponglet", card games, and several maze games. All the applets I've tried from them actually work (some typos in the book itself, but the CD is ok). Any of these could be "starter" code.
Yahoo has a whole bunch of Java applet games. You could try to reproduce pieces of the games you see. (These are also interesting in the sense that you can immediately see what works in a game and what doesn't.)
It is always fun to write little components. Cool buttons (write a nice little non-rectangular button that lights up or something), text boxes that look like digital displays, funny text labels (maybe with a weird font or with letters that jump all over the place when you mouse over them).. These don't take a whole lot of time to write, but write them well and they are very useful for your future games.
Enjoy!
:) jen -
I'm stuck in iPhone Developer Program set up that i never started, how do I get my iPod to skip this and just work like normal?
Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
If recovery mode does not work try DFU mode.
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings -
Need a simple program equivalent to the PC paint
I need a simple program that is equivalent to the Windows paint program thats free.
Does Paintbrush do what you want?
(30512) -
Please help me with simple program
Can someone please write a simple program for me that opens up a webpage in the center of the screen , with a set size, and then asks the user where they would like to click on the screen. Then once the person clicks it asks how many times they would like to click there, and then once they enter the # the program opens up the webpage (in the center at the same spot as before, with the same set size) and automatically clicks on the predesignated spot , and then closes all open internet windows, and keeps doing it for however many times the person chose. PLEASE HELP ME WITH THIS!!! If you could, please post the source code here. Thank you so much to whoever helps me!!!!!!!
If it's not to learn, then what is the purpose of
this project?well, if it's not HW and its not for learning java, then why the hell would anyone like to have a program that may open a webpage and then repeatedly click on predefined place...
let me see...
now if he had asked for program that fakes IP as well, then i would suggest that he tryes to generate unique clicks, but now... i'm not sure... maybe just voting in some polls or smthing... though, i would not create a program that clicks on the link or form element, but rather just reload url with given parameters for N times... -
JMS: simple program (urgent please)
I am quite new with the JMS. I am trying to have a simple program running in order to start from it towards the application I want to build.
I tried to run the sample program below:
package chat;
import javax.jms.*;
import javax.naming.*;
import java.io.*;
import java.io.InputStreamReader;
import java.util.Properties;
public class Chat implements javax.jms.MessageListener {
private TopicSession pubSession;
private TopicSession subSession;
private TopicPublisher publisher;
private TopicConnection connection;
/* Constructor. Establish JMS publisher and subscriber */
public Chat() throws Exception {
// Obtain a JNDI connection
Properties env = new Properties();
// ... specify the JNDI properties specific to the vendor
InitialContext jndi = new InitialContext(env);
// Look up a JMS connection factory
TopicConnectionFactory conFactory =
(TopicConnectionFactory) jndi.lookup("TopicConnectionFactory");
// Create a JMS connection
TopicConnection connection =
conFactory.createTopicConnection();
// Create two JMS session objects
TopicSession pubSession =
connection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
TopicSession subSession =
connection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
// Look up a JMS topic
Topic chatTopic = (Topic) jndi.lookup("anytopic");
// Create a JMS publisher and subscriber
TopicPublisher publisher =
pubSession.createPublisher(chatTopic);
TopicSubscriber subscriber =
subSession.createSubscriber(chatTopic);
// Set a JMS message listener
subscriber.setMessageListener(this);
// Intialize the Chat application
set(connection, pubSession, subSession, publisher);
// Start the JMS connection; allows messages to be delivered
connection.start();
/* Initialize the instance variables */
public void set(TopicConnection con, TopicSession pubSess,
TopicSession subSess, TopicPublisher pub) {
this.connection = con;
this.pubSession = pubSess;
this.subSession = subSess;
this.publisher = pub;
/* Receive message from topic subscriber */
public void onMessage(Message message) {
try {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
System.out.println(text);
} catch (JMSException jmse) {
jmse.printStackTrace();
/* Create and send message using topic publisher */
protected void writeMessage(String text) throws JMSException {
TextMessage message = pubSession.createTextMessage();
publisher.publish(message);
/* Close the JMS connection */
public void close() throws JMSException {
connection.close();
/* Run the Chat client */
public static void main(String[] args) {
try {
Chat chat = new Chat();
// Read from command line
BufferedReader commandLine = new
java.io.BufferedReader(new
InputStreamReader(System.in));
// Loop until the word "exit" is typed
while (true) {
String s = commandLine.readLine();
if (s.equalsIgnoreCase("exit")) {
chat.close(); // close down connection
System.exit(0); // exit program
} else {
chat.writeMessage(s);
} catch (Exception e) {
e.printStackTrace();
But at the line
�TopicConnectionFactory conFactory =
(TopicConnectionFactory) jndi.lookup("TopicConnectionFactory");�
I got this exception:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at chat.Chat.<init>(Chat.java:24)
at chat.Chat.main(Chat.java:94)
I realize that the problem is in the jndi setup. But, the problem is that I do not know where to go now and what should I do. I do not know how can I get the jndi.properties file and where and how to put it.
Please, kindly advise from your experience. I would appreciate clear steps to have this program running properly. Otherwise, if you do have a sample program that is already running, please provide it to me.Thank you for your prompt reply.
I tried another example.
package test;
javax.jms.*;
import javax.naming.*;
public class SimpleTopicPublisher { /** * Main method. * * @param args the topic used by the example and, * optionally, the number of messages to send */
public static void main(String[] args) {
String topicName = null;
Context jndiContext = null;
TopicConnectionFactory topicConnectionFactory = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicPublisher topicPublisher = null;
TextMessage message = null;
final int NUM_MSGS;
// if ((args.length < 1) || (args.length > 2)) {
// System.out.println("Usage: java " + "SimpleTopicPublisher " + "[]");
// System.exit(1);
topicName = new String("MyTopic");
System.out.println("Topic name is " + topicName);
if (args.length == 2) {
NUM_MSGS = (new Integer(args[1])).intValue();
} else {
NUM_MSGS = 1;
/* * Create a JNDI API InitialContext object if none exists * yet. */
try {
jndiContext = new InitialContext
} catch (NamingException e) {
System.out.println("Could not create JNDI API " + "context: " +
e.toString());
e.printStackTrace();
System.exit(1);
/* * Look up connection factory and topic. If either does * not exist, exit. */
try {
topicConnectionFactory = (TopicConnectionFactory) jndiContext.
lookup("TopicConnectionFactory");
topic = (Topic) jndiContext.lookup(topicName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " + e.toString());
e.printStackTrace();
System.exit(1);
/* * Create connection. * Create session from connection; false means session is * not transacted. * Create publisher and text message. * Send messages, varying text slightly. * Finally, close connection. */
try {
topicConnection = topicConnectionFactory.createTopicConnection();
topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
topicPublisher = topicSession.createPublisher(topic);
message = topicSession.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message
.setText("This is message " + (i + 1));
System.out.println("Publishing message: " + message.getText());
topicPublisher.publish(message);
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
} finally {
if (topicConnection != null) {
try {
topicConnection.close();
} catch (JMSException e) {}
It is mentioned in SUN JMS tutorial that "When you use the J2EE SDK 1.3.1, your JMS provider is the SDK. " So I am using that and I did the follwoing:
--start the J2EE server as follows:
j2ee -verbose
Then I created the adminstrated object:
j2eeadmin -addJmsDestination MyTopic topic
But still getting this error:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
So now where is the error?
Thank you in advance -
How to Run a simple program using JMS Queue.!!
Hi All,
I am trying to run simple program on JMS Queue.
Using SOA Suite 10.1.3.2
I created a connection factory and queue using EM.
Connection Factory => Domain : Queue JNDI Location : jms/sidConnectionFactory
Queue Name : SidQueue JNDI Location : jms/SidQueue
Tried running a simple java class to send the messages to queue.[Pls find the file attached].
Getting this error
javax.naming.NamingException: META-INF/application-client.xml not found (see J2EE spec, application-client chapter for requirements and format of the file)
at oracle.j2ee.naming.ApplicationClientInitialContextFactory.getRequiredClasspathResource(ApplicationClientInitialContextFactory.java:239)
at oracle.j2ee.naming.ApplicationClientInitialContextFactory.getArchive(ApplicationClientInitialContextFactory.java:161)
at oracle.j2ee.naming.ApplicationClientInitialContextFactory.getInitialContext(ApplicationClientInitialContextFactory.java:111)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
Can some one tell me how i need to create this file and where to place this[i.e is this need to be placed in my project or some directory structure of <SOA-HOME>
Thx,
Siddhardha.
Code:
package demo;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class JMSQueue {
public static void main(String args[])
QueueConnection queueConnection;
QueueSession queueSession;
//private MessageProducer producer;
QueueSender queueSender;
try {
String message = "Test";
String connectionFactoryName = "jms/sidConnectionFactory";
String destinationName = "jms/SidQueue";
/*Do i need to use this .......
* If so where is the error in below statements...
* Properties env = new Properties( );
// ... specify the JNDI properties specific to the vendor
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "welcome");
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.evermind.server.ApplicationClientInitialContextFactory");
env.put(Context.PROVIDER_URL,
"ormi://localhost:23791");
Context ctx = new InitialContext();
// Get the connection factory.
QueueConnectionFactory cf = (QueueConnectionFactory)ctx.lookup(connectionFactoryName);
// Get the destination.
Queue destination = (Queue) ctx.lookup(destinationName);
// Use the connection factory to create a connection.
queueConnection = cf.createQueueConnection();
// Start the connection.
queueConnection.start();
// Use the connection to create a session.
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// Use the session and destination to create a message producer and a message consumer.
//producer = queueSession.createProducer(destination);
queueSender = queueSession.createSender(destination);
TextMessage msg = queueSession.createTextMessage(message);
queueSender.send(msg);
queueSession.close();
queueConnection.close();
catch (Exception ex) {
ex.printStackTrace();
* Attached following libraries to the Project
* jms.jar
* optic.jar
* oc4jclient.jar
*/Hi,
You need to change the INITIAL_CONTEXT_FACTORY to com.evermind.server.RMIInitialContextFactory.
Regards,
Sandeep -
Even a simple program is not working ?
Hi there,
I typed a simple program to display the customer details. The program goes like this :
import java.lang.*;
public class Customer
String custname;
String custID;
public Customer()
custname = "Bob";
custID = "S20010";
public void displaydetails()
System.out.println("Customer name is " + custname);
System.out.println("Customer ID is " + custID);
public static void main(String a[])
Customer cust = new Customer();
cust.displaydetails();
The compilation went right. But, when I executed the program the following error message is displayed :
c:\>java Customer.java
Exception in thread "main" java.lang.NoClassDefFoundError: Customer/java.
Please help !!Don't cross-post.
http://forum.java.sun.com/thread.jspa?threadID=576890&messageID=2891064#2891064 -
Help with a simple program.
I need some help writing a simple program. Can anybody help??
thanks to all.
2. HTML Java Source Code Reserved Word Highlighter
Write a program that inputs a Java source code file and outputs a copy of that file with Java keywords surrounded with HTML tags for bold type. For example this input:
public class JavaSource
public static void main ( String[] args )
if ( args.length == 3 )
new BigObject();
else
System.out.println("Too few arguments.");
will be transformed into:
<B>public</B> <B>class</B> JavaSource
<B>public</B> <B>static</B> <B>void</B> main ( String[] args )
<B>if</B> ( args.length == 3 )
<B>new</B> BigObject();
<B>else</B>
System.out.println("Too few arguments.");
In a browser the code will look like this:
public class JavaSource
public static void main ( String[] args )
if ( args.length == 3 )
new BigObject();
else
System.out.println("Too few arguments.");Here is something that may get you started...
import java.io.*;
import java.util.*;
public class HtmlJava{
public static void main(String arg[]){
if(arg.length!=1){
System.out.println("Usage java HtmlJava sourceFile");
else
new HtmlJava(arg[0]);
HtmlJava(String source){
try{
BufferedReader sourceReader=new BufferedReader(new InputStreamReader(new FileInputStream(source)));
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(source+"Html.txt")));
Vector keywords=new Vector();
addKeywords(keywords);
String line;
StringTokenizer tokenizer=null;
String word;
while((line=sourceReader.readLine () )!=null){
tokenizer=new StringTokenizer(line);
while(tokenizer.hasMoreTokens()){
word=tokenizer.nextToken();
if(keywords.contains(word)){
writer.write(""+word+" ");
else{
writer.write(word+" ");
writer.write("\r\n");
writer.close();
sourceReader.close();
System.out.println("Output File written to "+source+"Html.txt");
catch(Exception ex){
ex.printStackTrace();
private void addKeywords(Vector keywords){
keywords.addElement ( "abstract");
keywords.addElement( "boolean");
keywords.addElement( "break");
keywords.addElement( "byte");
keywords.addElement( "byvalue");
keywords.addElement( "case");
keywords.addElement( "cast");
keywords.addElement( "catch");
keywords.addElement( "char");
keywords.addElement( "class");
keywords.addElement( "const");
keywords.addElement( "continue");
keywords.addElement( "default");
keywords.addElement( "do");
keywords.addElement( "double");
keywords.addElement( "else");
keywords.addElement( "extends");
keywords.addElement( "false");
keywords.addElement( "final");
keywords.addElement( "finally");
keywords.addElement( "float");
keywords.addElement( "for");
keywords.addElement( "future");
keywords.addElement( "generic");
keywords.addElement( "goto");
keywords.addElement( "if");
keywords.addElement( "implements");
keywords.addElement( "import");
keywords.addElement( "inner");
keywords.addElement( "instanceof");
keywords.addElement( "int");
keywords.addElement( "interface");
keywords.addElement( "long");
keywords.addElement( "native");
keywords.addElement( "new");
keywords.addElement( "null");
keywords.addElement( "operator");
keywords.addElement( "outer");
keywords.addElement( "package");
keywords.addElement( "private");
keywords.addElement( "protected");
keywords.addElement( "public");
keywords.addElement( "rest");
keywords.addElement( "return");
keywords.addElement( "short");
keywords.addElement( "static");
keywords.addElement( "super");
keywords.addElement( "switch");
keywords.addElement( "synchronized");
keywords.addElement( "this");
keywords.addElement( "throw");
keywords.addElement( "throws");
keywords.addElement( "transient");
keywords.addElement( "true");
keywords.addElement( "try");
keywords.addElement( "var");
keywords.addElement( "void");
keywords.addElement( "volatile");
keywords.addElement( "while");
}Hope it helped -
How to create a simple program
I downloaded JBuilder Foundation and it looks very complicated. I thought I could start a new project like you can in C++ Builder and choose "console application" and it would bring you to the code window with nothing in it or perhaps just a header file or two. But when I create a new project it brings me to a code window with a whole bunch of complicated code already there. And I don't understand any of it. Really what I want to be able to do is start a new project and just type this into the code window:
public class Welcome1 {
public static void main(String args[ ])
System.out.println("Welcome to Java!");
And then click Run and it outputs:
Welcome to Java!
But I don't know how to do that in this JBuilder. I may need to switch to another IDE or maybe just download a text editor and the Java SDK. If you can tell me what I should do that would be good. Thanksdownload a text editor and the Java SDK.I'd recommend that. It's easy to learn an IDE afterwards, but many people are incapable of writing and compiling code without an IDE because they don't know how javac works etc.
For simple programs a text editor is more than enough, then once you get your head around the classpath, you're home free! -
Any simple program available for testing instant client for Windows
Any simple program available for testing installation of instant client for Windows.
Thankx in advanceHaving a program means you need a dev environment to compile, link and then test it with your instant client env.
I would suggest you download sqlplus ZIP and connect to a DB server. -
I need a simple program to convert flac files to mp3 with album art
Is there a fairly simple program that will convert files and imbed album art by track? All of my music files are flac with album art included in the album folder.
Not sure of any software that will do the conversion and automatically embed album art, but LameDropXPD is a free, super-simple drag and drop conversion tool that will accept flac input: http://www.rarewares.org/mp3-lamedrop.php#lamedrop-current and MP3Tag (also free) has an option to do batch embedding of album art.
-
How can i make simple program to match colors ?(photos taken by camera)
how can i make simple program to match colors ?(photos taken by camera)
Hi khaledyr,
use a "random number" and compare for ">0.5" to get a (1 or 0) signal
What exactly are you searching for?
- Hints for choosing hardware?
- How to output voltage or relais signals?
- Help on using DAQ(mx)?
- Help on generating (boolean) waveforms?
Message Edited by GerdW on 04-16-2010 08:15 AM
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome
Maybe you are looking for
-
Illustrator CS4: Images Open 3x Smaller than Original
Every time I open an image in Illustrator, it is 3-times smaller than the original image started out. For example: An image starting out with the dimensions: Width: 5.35 inches / 1070 px / 385.2 pt Height: 5.24 inches / 1048 px / 377.3 pt Once it is
-
Xperia Z2 screen flickers white color white screen is on after receiving notification
I would like to bring to your notice that i bought new xperia z2 on 14 june 2015, the next day onwards i faced display problem ( screen flickers), i recorded that as evidence and submitted for DOA request after many follow ups i got approval. Yesterd
-
I've searched high and low on my account for a way to change the name of my business but I just can't find out how to do it. Ideally I would actually like to turn the account back into a personal account but that also doesn't seem to be an option and
-
Activation of Objects with Type Data Transfer Process
Hi Experts, I am stuck in a problem of activation of DTP. I loaded the data from the Datasource to PSA and there are about 200,000 reocrds. Now I wanted to take this load to DSO NEW table ..I have created a DTP and when I try to activate the DTP I ge
-
E51 : How to Display Calling Number
Help : How to Display the Calling Number along with Contact Number from the Address book when Receving Call from the number stored in the address book. Eg : Last Name : Z First Name : A Mobile : +1 12 123465789 Tel(Home) : +1 12 987654321 Tel(Office)