• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

ThinkingsHard

Members
  • Content count

    38
  • Joined

  • Last visited

Community Reputation

236 Neutral

About ThinkingsHard

  • Rank
    Member
  1. I recommend you work on creating some console games and then move on to creating some gui games. I took a class in C# this semester, because I previously had taken an intro to Java class, which had given me info on loops and arrays, one of our projects was to create a console game. I create minesweeper, where you just selected your position by typing it in. It was actually pretty fun to make.   The point is, is that you'll gain a lot more from hands on experience than from reading from the book, in my opinion. I've read sections of my textbook 10 times over and still don't know what I'm doing, I go to implement it,  it doesn't work. I get it working, I kinda understand better. Again this is all just personal opinion, but if you can create something simple from scratch, like a pong game, and you understand it perfectly well, it doesn't really take all that long. You could probably make the entire game in about 2-3 hours if you understood everything, and yet it took a group of us in class 2 weeks to get it working properly when we were still learning that stuff.   (Also in case this is understood as such, I'm not saying don't read the books, they are great, I'm saying to practice the stuff you traditionally see in the first 8 or so chapters of a programing book (Which is like, creating strings, ints, doubles, floating points, printing out statements, sending information to the program with input, arrays, loops, drawing shapes) because for me and my class, it's poor understanding of those first semester / second semester concepts that are causing issues, not the higher up database and networking stuff)
  2. How I built this so far was I started, before I added gui elements, I had it at a simple console input is then sent to server, and then the server responds. I know the problem is in the code I linked. The "component.text()" is a reference to a JTextField. The class that holds the code I showed you, has two inner classes. Everything works except what I've mentioned about the input is stuck in an infinite loop. The code I linked is working code for A SINGLE interation. If I surround while(connected) { System.out.println("Type in a word to send to the server."); // Sends the word to the server from the TextField System.out.print("Sending: " + component.text() + "\n"); out.println(component.text()); out.flush(); // gets the Response from the server response = in.nextLine(); if(!response.equals("Word does not exist")) { wordList.add(response); System.out.println("Receiving: " + response + "\n"); } for(String str: wordList) { System.out.println(wordCount); wordCount++; } } the stuff I WANT to do with a while statement, it keeps adding the last input to the ArrayList and keeps increasing wordCount endlessly. Basically.   For pseudo code.   I want to continue to listen for input from the user Check it against the dictionary if it's a real word, send it back from the server to the client add that word to an ArrayList increase the wordCount (really just there to determine if I've finally got it working so it will only add one word to the ArrayList for that input)   Repeat this process for the duration the game is running.   In the event that I am wrong about everything else working in my code, I will supply the entire 3 classes I am working with.   The Client (That controlls the words used): import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.BufferedReader; import java.io.File; import java.io.InputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.net.Socket; import java.util.ArrayList; import java.util.Scanner; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class ControllerClient { static boolean connected = true; public static String response = "test"; public static ClientComponent component; public static int wordCount = 0; public static String wordCountString = ""; public static void main(String[] args) throws IOException { component = new ClientComponent(); final int SBAP_PORT = 8888; //Creates a frame JFrame frame = new JFrame(); frame.setSize(1080,720); frame.add(component); frame.setVisible(true); //creates a socket // with a input and output stream Socket s = new Socket("localhost", SBAP_PORT); InputStream instream = s.getInputStream(); OutputStream outstream = s.getOutputStream(); Scanner in = new Scanner(instream); PrintWriter out = new PrintWriter(outstream); ArrayList<String> wordList = new ArrayList<String>(); // Creates a scanner to read input from the keyboard Scanner input = new Scanner(System.in); // instantiates a string for use with the input from the user String command = ""; // While connected is true, then prompt the user to send words to the server System.out.println("Type in a word to send to the server."); // Sends the word to the server from the TextField System.out.print("Sending: " + component.text() + "\n"); out.println(component.text()); out.flush(); // gets the Response from the server response = in.nextLine(); if(!response.equals("Word does not exist")) { wordList.add(response); System.out.println("Receiving: " + response + "\n"); } for(String str: wordList) { System.out.println(wordCount); wordCount++; } s.close(); } } class ClientComponent extends JComponent { private Object setLayout; public JTextField controllerInput; public TextFieldKeyListener textListener; public ClientComponent() { // creates the TextField and sets it's bounds controllerInput = new JTextField(); this.setLayout = null; textListener = new TextFieldKeyListener(this); controllerInput.setBounds(50, 480, 1000, 30); controllerInput.setText("Type here"); this.add(controllerInput); controllerInput.setVisible(true); controllerInput.addKeyListener(textListener); } // draw method public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setFont(new Font("TimesRoman", Font.PLAIN, 15)); g2.drawString(String.valueOf(ControllerClient.wordCount), 10, 10); g2.drawString(ControllerClient.response, 320, 30); //text(); } public void update() { Graphics g = getGraphics(); controllerInput.setText(""); controllerInput.hasFocus(); //paint(g); repaint(); } public String text() { return textListener.getTextField(); } } class TextFieldKeyListener implements KeyListener { public String text; public ClientComponent gamePanel; public TextFieldKeyListener(ClientComponent gamePanel) { this.gamePanel = gamePanel; } @Override /** * Gets the key press event for the text field */ public void keyPressed(KeyEvent event) { // makes sure that the key is the enter key before actually working if(event.getKeyCode() == KeyEvent.VK_ENTER) { JTextField textField = (JTextField) event.getSource(); text = textField.getText(); gamePanel.update(); } // if it's not, do nothing else { } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } //returns the text in the textfield public String getTextField() { return text; } } The Service (Runnable Thread): import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.net.Socket; import java.util.Scanner; public class ControllerService implements Runnable { private Socket s; private Scanner in; private PrintWriter out; private File aFile = new File("Dictionary.txt"); public ControllerService(Socket aSocket) { s = aSocket; } public void run() { System.out.println("Has reached run method of ControllerService"); try { try { in = new Scanner(s.getInputStream()); out = new PrintWriter(s.getOutputStream()); while(true) { doService(); } } finally { s.close(); } } catch (IOException exception) { exception.printStackTrace(); } } public void doService() throws IOException { System.out.println("Has reached doService method of ControllerService"); String command = in.next(); command = command.toLowerCase(); executeCommand(command); } public void executeCommand(String command) throws FileNotFoundException { System.out.println("In the executeCommand method"); Scanner scanFile = new Scanner(new File("Dictionary.txt")); int val = 0; //While the value is not 2 while(val != 2) { // Prints out a line to tell me it has reached the first loop of the method System.out.println("In the executeCommand first loop of the method"); // while the Dictionary file has another line while(scanFile.hasNextLine()) { // Prints out to tell me it has reached the inner loop System.out.println("In the executeCommand second loop of the method"); // Creates a string that is the word on that line of the dictionary file String line = scanFile.nextLine(); // if line.indexOf command doesn't return -1(which is false, meaning // that it wasn't that word //Then it returned 1, which means it WAS that word if(line.indexOf(command) != -1) { // sends the word back to the client // and breaks out of the loop out.print(command +"\n"); out.flush(); val= 2; break; } // the value stays 1 if the above is not true else { val = 1; } } // if the value is 1 after the loop, the the word does not exist in the file if(val == 1) out.print("Word does not exist\n"); out.flush(); val=2; } } } The Server: import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; public class GameServer { public static void main(String[] args) throws IOException { final int C_PORT = 8888; ServerSocket controller = new ServerSocket(C_PORT); System.out.println("Waiting for clients..."); Socket controllerPlayer = controller.accept(); System.out.println("Clients connected...."); ControllerService cService = new ControllerService(controllerPlayer); Thread cPlayer = new Thread(cService); int val = 1; cPlayer.start(); } }
  3. Yes. The program is a networked 3+ player game. I'm currently only working on one client, and that is a special client. Before I get into that, the overall game is basically a 'word attack' Where words will fall from the top of the frame to the bottom of the players screens, and they have to correctly type the word in. They get points for doing so, and the words fall at different speeds depending on the size of the word, with smaller words falling faster than larger words. There is an overall time limit , and if none of the players lose all 3 of their lives (working on just 2 players fighting eachother for now), and they don't reach whatever point limit I create for winning, then lives get converted to points and the winner is determined on overall points. The special client has a frame that will allow him/her to see the other players screens, and then a blank text field. This user controlls what words fall down the screen. Anything they type into that text field, is sent to a process that determines if that word is in the dictionary, and then it removes any upper case characters, replaces them so the entire word is lower case, and sends that word back from the server to the client(s).   I'm trying to get it so that when this special client submits a word, if it is a word that passed the screening of if it is or is not in the dictionary, then it is added to a list. This list will be used later. Right now, this list continues to get populated with the same word. So if your word was 'what' You'd get a list like what what what what what... etc.   Right now, I want it to take that, and make it so if you submit what, you get what *waits for next word*
  4. Socket s = new Socket("localhost", SBAP_PORT); InputStream instream = s.getInputStream(); OutputStream outstream = s.getOutputStream(); Scanner in = new Scanner(instream); PrintWriter out = new PrintWriter(outstream); ArrayList<String> wordList = new ArrayList<String>(); // Creates a scanner to read input from the keyboard Scanner input = new Scanner(System.in); // instantiates a string for use with the input from the user String command = ""; // While connected is true, then prompt the user to send words to the server System.out.println("Type in a word to send to the server."); // Sends the word to the server from the TextField System.out.print("Sending: " + component.text() + "\n"); out.println(component.text()); out.flush(); // gets the Response from the server response = in.nextLine(); if(!response.equals("Word does not exist")) { wordList.add(response); System.out.println("Receiving: " + response + "\n"); } for(String str: wordList) { System.out.println(wordCount); wordCount++; } Everything underneith //While connected is true... Is what I want to have loop infinitely, however, I want it to loop back through, and wait for the user to input again before continuing. As it is now, if I have a while{ ... } loop around all that, it keeps adding the response to the wordList ArrayList, and since it continues to repeat that, wordCount continues to increase also.   I'm still currently trying to think of a way to get this loop to halt and wait before continuing. Google searches for making a loop wait kept bringing up threading and using wait() and notify() on threads... and this is not a threading issue, lol.   Thank you for your time.
  5. I fixed it by using this code public void encrypt2(String str, String key) { for (int i = 0; i < str.length(); i++) { char baelleCh = str.charAt(i); char ch = key.charAt(i % key.length()); // allows spaces if(baelleCh == ' ') { cryptedString2 += baelleCh; } else { // like the Ceasar Cipher, takes the char in the string, minus 'a' plus the numerical value of the character of the key, mod 26, plus 'a' char encoding = (char) (((baelleCh - 'a') + (ch-'a')) % 26 + 'a'); cryptedString2 += encoding; } } }
  6. public void encrypt2(String str, String key) { for (int i = 0; i < str.length(); i++) { char baelleCh = str.charAt(i); char ch = key.charAt(i % key.length()); if(baelleCh == ' ') { cryptedString2 += baelleCh; } char encoding = (char) (((baelleCh - 'a') + (ch - 'a')) % 26 + 'a'); cryptedString2 += encoding; } It works now, the only problem is, it adds characters like \ and _. Is there a way to make it not have these when it's encrypting the string? I can't really think of anything that would remove them without messing with the encryption. editting this to add that If I change it to    char encoding = (char) (((baelleCh - 'a') + (Character.getNumericValue(ch)%26 + 'a')) % 26 + 'a');   I get a neater string with no odd symbols, however I then run into a problem of, I'm having it not align the words properly. There are spaces, and it's spaced out and looks nice, however there is a 3 letter encrypted string where a 2 letter string should be, same for a 4 and a few 6's. It's quite strange. I'm not sure why.
  7. Attempting to convert that over to Java.   It keeps getting annoyed saying key needs to be an int. for (int i = 0; i < str.length(); i++) { char baelleCh = str.charAt(i); char ch = key.charAt(i); char encoding = (char)('A' + baelleCh - 'A' + key(i % key.length()) - 'A') % 26); cryptedString2 += encoding; }
  8. I'm having trouble getting the Beale Cipher to work. For anyone unfamiliar, it's basically the ceasar cipher, only a bit cooler.       Take the decrypted message from the first cryptogram, and  have it be the key to solving the next cipher. How this cipher works 0123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 (These values can be anything that you really want, I set a to zero instead of abcde fgh i j    k   l    m  n   o  p    q   r   s    t   u    v   w  x   y  z    1 just for the hell of it) Key:                “STRINGOFWORDSSTRINGOFWORDSSTRINGOFWORDS...” Message         “THEPROBLEMISNOTTHEPROBLEMTHEPROBLEMISYOURATTITUDEABOUTTHEPROBLEM,DOYOUUNDERSTAND” Encryption:  S = 18. S applies to the T of the first letter of the message. Shift T 18 letters T becomes L “LAVXFU…”   I have two problems. Right now, it's not properly encrypting. And the second problem, is, as you can see, the key isn't always going to be the same length of the message, but I'm failing to think of a loop that will take the key message, and continue to add it onto itsself until it reaches the length of the message you want to encrypt. public void encrypt2(String str, String key) { /*for(int z = 0; z < str.length(); z++) { char kCh = key.charAt(z); key += kCh; }*/ for(int i= 0; i < str.length(); i++) { // the Character in the string char baelleCh = str.charAt(i); for(int k=0; k < key.length(); k++) { // The character in the key char ch = key.charAt(i); // if the character in the key is a space if(ch == ' ') { // crypted = the character char crypted = ch; cryptedString2 += crypted; // the character is added onto the string } else if(ch == 'a') { shift = 0; // shift is nothing char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); // crypted is set to the character in the string minus value of a, plus the shift cryptedString2 += crypted; // mod 26 for the alphabet, plus the value of a } else if(ch == 'b') { shift = 1; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'c') { shift = 2; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'd') { shift = 3; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'e') { shift = 4; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'f') { shift = 5; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'g') { shift = 6; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'h') { shift = 7; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'i') { shift = 8; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'j') { shift = 9; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'k') { shift = 10; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'l') { shift = 11; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'm') { shift = 12; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'n') { shift = 13; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'o') { shift = 14; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'p') { shift = 15; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'q') { shift = 16; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'r') { shift = 17; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 's') { shift = 18; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 't') { shift = 19; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'u') { shift = 20; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'v') { shift = 21; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'w') { shift = 22; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'x') { shift = 23; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'y') { shift = 24; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else if(ch == 'z') { shift = 25; char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); cryptedString2 += crypted; } else { System.out.println("Bug; did not reach a letter"); } } } } I will be available to answer any questions in regards to this through this post or private message. I'm hoping to have this completed ASAP as it's what I'm working on for my final project this semester.
  9. Solved... my images were not in the folder 'images'. >.<.
  10. I would have done it that way, except this was a project that was given to us to have us convert radiobuttons over to JMenuItems.   For my Final I've done things that way, where I get one thing working, before trying to get anything else working.
  11. There is no exception or errors. I tried minimizing. I'm going to look into the JLabel. Thanks.
  12. Updated version of the first class. Now my only issue is that it doesn't display the images. /** This frame will display a picture that the user selects using radio buttons. @author: Harv @version: 5/8/14 - 5/9/14 */ import java.awt.* ; // for FlowLayout and Dimension classes import javax.swing.*; // for Swing components import java.awt.event.* ; // for ActionListener interface import javax.swing.BorderFactory; import javax.swing.border.Border; @SuppressWarnings("serial") public class ImageViewerFrame extends JFrame { // Instance variables String [] descriptions = new String[6]; // 1 description per image String [] pictures = new String[6]; Border loweredbevel = BorderFactory.createLoweredBevelBorder(); // Set up the border JPanel headingPanel; JPanel controlPanel; JLabel pictureLabel; JLabel headingLabel; JLabel instructionsLabel; JTextArea outputTextArea; // I could have used a label containing HTML to create a multiple row label JMenu fileMenu = new JMenu("File"); JMenu aboutMenu = new JMenu("About"); JMenu imageMenu = new JMenu("Images"); JMenuItem image1 = new JMenuItem("Gregory Lake"); JMenuItem image2 = new JMenuItem("Devils Post Pile"); JMenuItem image3 = new JMenuItem("JMT Sign"); JMenuItem image4 = new JMenuItem("Lonely Tree"); JMenuItem image5 = new JMenuItem("View From Whitney"); JMenuItem image6 = new JMenuItem("Lone Pine Lake"); JMenuItem exit = new JMenuItem("Exit"); JMenuItem about = new JMenuItem("About"); // constructor public ImageViewerFrame(){ // Helper methods loadPictureInformation(); createHeadingPanel(); createOutputArea(); createMenuPanel(); // Create the area where the pictures will be displayed pictureLabel = new JLabel(); pictureLabel.setIcon(new ImageIcon("images/" + pictures[0])); pictureLabel.setBorder(loweredbevel); // Add the components to the frame setLayout(new BorderLayout()); //add(controlPanel, BorderLayout.WEST); add(headingPanel, BorderLayout.NORTH); add(outputTextArea, BorderLayout.SOUTH); add(pictureLabel, BorderLayout.CENTER); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(fileMenu); menuBar.add(imageMenu); menuBar.add(aboutMenu); imageMenu.add(image1); imageMenu.add(image2); imageMenu.add(image3); imageMenu.add(image4); imageMenu.add(image5); imageMenu.add(image6); fileMenu.add(exit); aboutMenu.add(about); } class ImageListener implements ActionListener { public void actionPerformed(ActionEvent event) { JMenuItem imageName; imageName = (JMenuItem)event.getSource(); /** * Finds what the imagename equals * then finds that image and displays it */ if(imageName.getText().equals(image1)) { outputTextArea.replaceRange(descriptions[0], 0, outputTextArea.getText().length()); pictureLabel.setIcon(new ImageIcon("images/" + pictures[0])); } else if(imageName.getText().equals(image2)) { outputTextArea.replaceRange(descriptions[1], 0, outputTextArea.getText().length()); pictureLabel.setIcon(new ImageIcon("images/" + pictures[1])); } else if(imageName.getText().equals(image3)) { outputTextArea.replaceRange(descriptions[2], 0, outputTextArea.getText().length()); pictureLabel.setIcon(new ImageIcon("images/" + pictures[2])); } else if(imageName.getText().equals(image4)) { outputTextArea.replaceRange(descriptions[3], 0, outputTextArea.getText().length()); pictureLabel.setIcon(new ImageIcon("images/" + pictures[3])); } else if(imageName.getText().equals(image5)) { outputTextArea.replaceRange(descriptions[4], 0, outputTextArea.getText().length()); pictureLabel.setIcon(new ImageIcon("images/" + pictures[4])); } else if(imageName.getText().equals(image6)) { outputTextArea.replaceRange(descriptions[5], 0, outputTextArea.getText().length()); pictureLabel.setIcon(new ImageIcon("images/" + pictures[5])); } } } /** Loads the arrays with the file name and description for each picture. */ public void loadPictureInformation() { // Load the file names for the pictures pictures[0] = "Gregory Lake.JPG"; pictures[1] = "Devils Post Pile.JPG"; pictures[2] = "JMT Sign.JPG"; pictures[3] = "Lonely Tree.JPG"; pictures[4] = "View From Whitney.JPG"; pictures[5] = "Lone Pine Lake.JPG"; // Load the descriptions for each picture descriptions[0] = "Gregory Lake is located between Yosemite Valley and Reds Meadow pack station on the John Muir Trail in California"; descriptions[1] = "Devils Post Pile was caused by the glaciers. It is part of Yosemite National Park, even though is located south of Yosemite."; descriptions[2] = "Not all signs on the trail were this nice. This was a nice reminder about the man that the trail was named for."; descriptions[3] = "The tree seems lonely. It is located approximately 2 days, by foot, before Mt. Whitney."; descriptions[4] = "Watching the sun rise from the summit of Mt. Whitney, the highest point in the continental US at 14,500 ft."; descriptions[5] = "The view from our last campsite on the John Muir Trail before reaching the end of the 220 mile backpack."; } class ExitItemListener implements ActionListener { public void actionPerformed(ActionEvent event) { System.exit(0); } } /** Create the area for the selecting which picture to display */ public void createMenuPanel() { // Register the listener ImageListener listener = new ImageListener(); image1.addActionListener(listener); image2.addActionListener(listener); image3.addActionListener(listener); image4.addActionListener(listener); image5.addActionListener(listener); image6.addActionListener(listener); ActionListener exitListener = new ExitItemListener(); exit.addActionListener(exitListener); ActionListener aboutListener = new AboutListener(); about.addActionListener(aboutListener); // Create the other components JPanel myMenuPanel = new JPanel(); myMenuPanel.setLayout(new GridLayout(0, 1)); } class AboutListener implements ActionListener { public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(null,"Harvey version: ohgodhowmanyversionsdidIdo?"); } } /** Create the heading area at the top of the window */ public void createHeadingPanel() { headingLabel = new JLabel("<html>Pictures from <br>the John Muir Trail</html>", SwingConstants.CENTER ); headingLabel.setFont(new Font("Comic Sans MS", Font.ITALIC, 24)); instructionsLabel = new JLabel("Select a picture from the menu to view", SwingConstants.CENTER); instructionsLabel.setFont(new Font("Comic Sans MS", Font.ITALIC, 18)); headingPanel = new JPanel(); headingPanel.setLayout(new GridLayout(0, 1)); headingPanel.add(headingLabel); headingPanel.add(instructionsLabel); headingPanel.setBackground(Color.LIGHT_GRAY); } /** Create the output area to display the descriptions of the pictures */ public void createOutputArea() { outputTextArea = new JTextArea(descriptions[0], 3, 20); // 3 rows, 50 columns, initially empty outputTextArea.setEditable(false); // make it be read only outputTextArea.setLineWrap(true); // allow it to wrap outputTextArea.setWrapStyleWord(true); // break lines between words outputTextArea.setBackground(Color.LIGHT_GRAY); outputTextArea.setForeground(Color.BLACK); outputTextArea.setFont(new Font("Comic Sans MS", Font.PLAIN, 14)); outputTextArea.setBorder(loweredbevel); } }
  13. /** This frame will display a picture that the user selects using radio buttons. @author: B.Brenner @version: 1/26/10 */ import java.awt.* ; // for FlowLayout and Dimension classes import javax.swing.*; // for Swing components import java.awt.event.* ; // for ActionListener interface import javax.swing.BorderFactory; import javax.swing.border.Border; @SuppressWarnings("serial") public class ImageViewerFrame extends JFrame{ // Instance variables String [] descriptions = new String[6]; // 1 description per image String [] pictures = new String[6]; Border loweredbevel = BorderFactory.createLoweredBevelBorder(); // Set up the border JPanel headingPanel; JPanel controlPanel; JLabel pictureLabel; JLabel headingLabel; JLabel instructionsLabel; JTextArea outputTextArea; // I could have used a label containing HTML to create a multiple row label JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu exitMenu = new JMenu("Exit"); JMenu aboutMenu = new JMenu("About"); JMenu imageMenu = new JMenu("Images"); JMenuItem image1 = new JMenuItem("Gregory Lake"); JMenuItem image2 = new JMenuItem("Devils Post Pile"); JMenuItem image3 = new JMenuItem("JMT Sign"); JMenuItem image4 = new JMenuItem("Lonely Tree"); JMenuItem image5 = new JMenuItem("View From Whitney"); JMenuItem image6 = new JMenuItem("Lone Pine Lake"); JMenuItem exit = new JMenuItem("Close"); String mName =""; // constructor public ImageViewerFrame(){ // Helper methods loadPictureInformation(); createHeadingPanel(); createOutputArea(); // Create the area where the pictures will be displayed pictureLabel = new JLabel(); pictureLabel.setIcon(new ImageIcon("images/" + pictures[0])); pictureLabel.setBorder(loweredbevel); // Add the components to the frame setLayout(new BorderLayout()); add(controlPanel, BorderLayout.WEST); add(headingPanel, BorderLayout.NORTH); add(outputTextArea, BorderLayout.SOUTH); add(pictureLabel, BorderLayout.CENTER); setJMenuBar(menuBar); menuBar.add(fileMenu); menuBar.add(imageMenu); menuBar.add(aboutMenu); menuBar.add(exitMenu); imageMenu.add(image1); imageMenu.add(image2); imageMenu.add(image3); imageMenu.add(image4); imageMenu.add(image5); imageMenu.add(image6); exitMenu.add(exit); } /** Loads the arrays with the file name and description for each picture. */ public void loadPictureInformation() { // Load the file names for the pictures pictures[0] = "Gregory Lake.JPG"; pictures[1] = "Devils Post Pile.JPG"; pictures[2] = "JMT Sign.JPG"; pictures[3] = "Lonely Tree.JPG"; pictures[4] = "View From Whitney.JPG"; pictures[5] = "Lone Pine Lake.JPG"; // Load the descriptions for each picture descriptions[0] = "Gregory Lake is located between Yosemite Valley and Reds Meadow pack station on the John Muir Trail in California"; descriptions[1] = "Devils Post Pile was caused by the glaciers. It is part of Yosemite National Park, even though is located south of Yosemite."; descriptions[2] = "Not all signs on the trail were this nice. This was a nice reminder about the man that the trail was named for."; descriptions[3] = "The tree seems lonely. It is located approximately 2 days, by foot, before Mt. Whitney."; descriptions[4] = "Watching the sun rise from the summit of Mt. Whitney, the highest point in the continental US at 14,500 ft."; descriptions[5] = "The view from our last campsite on the John Muir Trail before reaching the end of the 220 mile backpack."; } /** Create the area for the selecting which picture to display */ public void createMenuPanel() { // The code needed to react to a radio button being selected class MenuListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { //String menuName = ""; //menuName = (String) evt.getSource(); System.out.println("DEBUGGING" + (String) evt.getSource()); // mName = menuName; } } class ExitItemListener implements ActionListener { public void actionPerformed(ActionEvent event) { System.exit(0); } } /* ImageIcon imageIcon1 = new ImageIcon(pictures[0]); Image actualImage1 = imageIcon1.getImage(); ImageIcon imageIcon2 = new ImageIcon(pictures[1]); Image actualImage2 = imageIcon2.getImage(); ImageIcon imageIcon3 = new ImageIcon(pictures[2]); Image actualImage3 = imageIcon3.getImage(); ImageIcon imageIcon4 = new ImageIcon(pictures[3]); Image actualImage4 = imageIcon4.getImage(); ImageIcon imageIcon5 = new ImageIcon(pictures[4]); Image actualImage5 = imageIcon5.getImage(); ImageIcon imageIcon6 = new ImageIcon(pictures[5]); Image actualImage6 = imageIcon6.getImage(); */ // Register the listener ActionListener listener = new MenuListener(); image1.addActionListener(listener); image2.addActionListener(listener); image3.addActionListener(listener); image4.addActionListener(listener); image5.addActionListener(listener); image6.addActionListener(listener); ActionListener exitListener = new ExitItemListener(); exit.addActionListener(exitListener); // Create the other components JPanel myMenuPanel = new JPanel(); myMenuPanel.setLayout(new GridLayout(0, 1)); controlPanel = new JPanel(); controlPanel.setLayout( new GridLayout(0, 1) ); controlPanel.setBorder(loweredbevel); } /** Create the heading area at the top of the window */ public void createHeadingPanel() { headingLabel = new JLabel("<html>Pictures from <br>the John Muir Trail</html>", SwingConstants.CENTER ); headingLabel.setFont(new Font("Comic Sans MS", Font.ITALIC, 24)); instructionsLabel = new JLabel("Select a picture from the left to view", SwingConstants.CENTER); instructionsLabel.setFont(new Font("Comic Sans MS", Font.ITALIC, 18)); headingPanel = new JPanel(); headingPanel.setLayout(new GridLayout(0, 1)); headingPanel.add(headingLabel); headingPanel.add(instructionsLabel); headingPanel.setBackground(Color.LIGHT_GRAY); } /** Create the output area to display the descriptions of the pictures */ public void createOutputArea() { outputTextArea = new JTextArea(descriptions[0], 3, 20); // 3 rows, 50 columns, initially empty outputTextArea.setEditable(false); // make it be read only outputTextArea.setLineWrap(true); // allow it to wrap outputTextArea.setWrapStyleWord(true); // break lines between words outputTextArea.setBackground(Color.LIGHT_GRAY); outputTextArea.setForeground(Color.BLACK); outputTextArea.setFont(new Font("Comic Sans MS", Font.PLAIN, 14)); outputTextArea.setBorder(loweredbevel); } } /** Creates a frame to display pictures in @author: B.Brenner @verison: 1/26/2010 */ import javax.swing.JFrame; public class ImageViewer { /** Create a frame for the GUI. The remainder of the program is processed by the GUI. */ public static void main ( String[] args ){ // Create the frame and set its properties ImageViewerFrame viewerFrame = new ImageViewerFrame() ; viewerFrame.setSize( 580, 510 ); viewerFrame.setVisible( true ); viewerFrame.setTitle( "My Image Viewer" ); viewerFrame.setLocationRelativeTo(null); // center the frame on the screen viewerFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); viewerFrame.setResizable(false); // don't allow the frame to be resized } } So, I'm having trouble getting the actionlistener to draw the image when I click the appropriate image, also I've started getting a null pointer exception. I can't figure out what I'd want to put inside my action listener to respond to the JMenuItem to draw the appropriate image.  
  14. I might just be implementing this in the wrong areas then, because I've tried the solution from Vortez, and something similar to theslimdes method as well, and neither worked. So maybe it's just where I tried to get them to work.
  15. //package bouncingBoxes; import java.awt.Point; import java.awt.Rectangle; public class MyBox { private Rectangle box; private int dx; private int dy; private int speed = 1; private static final int BOX_WIDTH = 20; private static final int BOX_HEIGHT = 30; // constructor public MyBox(Rectangle box, int dx, int dy) { this.box = box; this.dx = dx; this.dy = dy; } // sets the vector public void setVector(int dx, int dy) { this.dx = dx; this.dy = dy; } // move the box public void move() { box.translate(dx, dy); } // moves the box just by the x coordinate public void moveX(int x) { dx = x; box.translate(dx, dy); } public void moveY(int y) { dy = y; box.translate(dx, dy); } public Rectangle getBox() { return box; } // gets the Y coordinate public int getDY() { return dy; } // gets the X coordinate public int getDX() { return dx; } public Point getNextLocation() { //next x position int x = (int)box.getX() + dx; int y = (int)box.getY() + dy; //return the next location return new Point(x,y); } public void bounceY() { //swap direction in the y direction dy *= -speed; speed++; } public void bounceX() { // swap direction in the x direction dx *= -speed; speed++; } //package bouncingBoxes; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.util.ArrayList; import javax.swing.JComponent; /** This component displays a rectangle that can be moved. */ public class RectangleComponent extends JComponent { private static final int BOX_WIDTH = 20; private static final int BOX_HEIGHT = 30; private ArrayList<MyBox> boxes; public RectangleComponent() { boxes = new ArrayList<MyBox>(); } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; for(MyBox box: boxes) { g2.draw( box.getBox() ); } } public void addRectangle(int x, int y, int dx, int dy) { Rectangle rect = new Rectangle(x, y, BOX_WIDTH, BOX_HEIGHT); MyBox box = new MyBox(rect, dx, dy); boxes.add(box); repaint(); } public void addRectangle(int x, int y) { Rectangle rect = new Rectangle(x, y, BOX_WIDTH, BOX_HEIGHT); MyBox box = new MyBox(rect, 4, 4); boxes.add(box); repaint(); } public void updateLocations() { for(MyBox box: boxes) { //get bottom after future move Point p = box.getNextLocation(); Rectangle r = box.getBox(); //if bottom of box will hit bottom of screen ... // or hits off of top if( (p.getY() + r.height > this.getHeight() ) || (p.getY() <=0) ) { //switch direction box.bounceY(); } if( (p.getX() + r.width > this.getWidth()) || (p.getX() <=0) ) { //switch direction box.bounceX(); } box.move(); } repaint(); } /* * Did not do what I had hoped * keep it here in event that I need it later * public void outOfBounds() { for(MyBox box: boxes) { if(box.getDX() > this.getWidth()) { int x = box.getDX() - this.getWidth(); box.moveX(x); } if(box.getDX() < 0) { int x = box.getDX(); box.moveX(-x); } if(box.getDY() > this.getHeight()) { int y = box.getDY() - this.getHeight(); box.moveY(y); } if(box.getDY() < 0) { int y = box.getDY(); box.moveY(-y); } } } */ } I'm trying to get this to work so that the rectangle will bounce off the walls, increasing speed as it bounces, however it will obviously increase so quickly that it will bounce out of the screen eventually. I want to find out when it goes out of bounds, then find the speed it was at when it went out of bounds, and then remove THAT speed by 1, without incrementing speed after it goes out of bounds, allowing it to stay fast, without causing the out of bounds speed again.  I'm kinda burned out from work and classes, and can't think. Anything anyone can do to help, even a bump in the right direction while I continue tot google search would be wonderful. Thank you.