Jump to content

devianthead

Member
  • Posts

    13
  • Joined

  • Last visited

Awards

About devianthead

  • Birthday Feb 20, 1991

Profile Information

  • Gender
    Male
  • Location
    Gauteng, South Africa
  • Occupation
    Software Engineer

System

  • CPU
    AMD Phenom II X6 @ 3.73Ghz
  • Motherboard
    Asus Crosshair V Formula-Z
  • RAM
    16Gb DDR3 1866
  • GPU
    EVGA GTX 970
  • Case
    Cooler Master CM 690 II Advanced
  • Storage
    256Gb Transcend SSD370
  • PSU
    650W thing
  • Display(s)
    Samsung 24" Full-HD
  • Cooling
    Cooler Master Hyper 212X
  • Keyboard
    Corsair Raptor K30
  • Mouse
    Gigabyte M8000X
  • Operating System
    Windows 10 Pro x64
  1. That's exactly right. I wouldn't use an array personally because it would make it a whole lot more difficult to read and understand. I'd rather have named instances of the button objects. So it would be something like... btnGetRecord.addActionListener(...);btnUpdateRecord.addActionListener(...);btnDisplayRecord.addActionListener(...); Then you could just use the object instance in the class to check for equality. So... public void actionPerformed(ActionEvent e) { if(e.getSource() == btnGetRecord){ // do something } else if (e.getSource() == btnUpdateRecord) { // do something else } else if (e.getSource() == btnDisplayRecord) { //do display things }} There are however, other ways to write ActionListeners that don't require you using getSource(). I'd advocate for the use of anonymous inner classes personally, those adhere a little more to the single responsibility principle https://en.wikipedia.org/wiki/Single_responsibility_principle. Ultimately, you'd definitely not want a single class that handled all of the actions for everything in your UI, so you could use an anonymous inner class to handle a single buttons event. But I assume you're doing this for a course of some kind, in which case, using getSource would be perfectly fine. EDIT: If you wanted to continue to use an array, then you could just get the text of the button from the source object. So you use the grouped if statements and just check for equality on the text contained on the button as follows. You'd just have to cast it into a JButton to be able to get the text. public void actionPerformed(ActionEvent e) { if(((JButton) e.getSource()).getText().equals("button text")){ // do something }}
  2. No problem. Just one tip when doing Swing layouts in Java is you need to try and think of how the JPanels nest within one another. When you're adding the "Update" label, you're right about the BorderLayout flag, but it won't work with a grid layout. You can see on the bottom right of the image you provided that "Display Records" has moved to the bottom right-most "cell" in the GridLayout. This is because when you insert items in the grid they fill up from the top left-most cell. So, to solve your problem. Try break the entire UI up into separate panels. It's just a different way of thinking about the problem. If you group common items into separate panels you can build the entire UI from the ground up. Each JPanel can then have it's own layout, and be inserted into other JPanels. Here's a YouTube video that could possibly explain how the JPanels could nest within one another. Full disclosure, not my video, but explains the concept. https://www.youtube.com/watch?v=Q4Vb-Ws7MO8
  3. Have a look at the way you're declaring your GridLayout. The GridLayout constructor takes in rows then columns. So all you have to do is just change the way you're declaring it. I count 6 rows and 2 columns, so all you have to do is change: grid = new GridLayout(2, 3); To... grid = new GridLayout(6, 2); For 6 rows and 2 columns. Here's a link to the documentation for GridLayout. https://docs.oracle.com/javase/tutorial/uiswing/layout/grid.html. Also, make sure your class name is capitalized. Hope that helps.
  4. Well, I recently posted a response to another thread much like this. Hope you don't mind me quoting because my reply would be the same.
  5. If it's for a school project you could always completely cut out the middleman. Write in Java and just make an applet. If its not going to be advanced, ie. no physics based stuff, it's entirely doable. In the beginning of my undergraduate we did a lot of Java and had to make games as well. It's pretty easy to learn the language and add the graphics stuff, also its really easy to find tutorials or example code. And you can easily create side scrollers with sprites, collision detection is also really easy. Granted, it's been a long time since I've had a need for writing an applet, so browser support may be finicky. But granted, it all depends on what exactly you're doing this for. If for a class, I'd say the simplest approach is better, then instead of focusing on learning the paradigms an engine implements you can concentrate on learning the language. Otherwise, if it's not for school, then go for broke and learn an engine by all means. Construct 2 looks really cool too.
  6. Don't know how useful you'd consider this, but here's an implementation of Bogosort written in Java just for fun, https://en.wikipedia.org/wiki/Bogosort. It's absolutely horrible, but it does sort the list . Lol I'd love to write Bogobogosort, guaranteed to only complete after the inevitable heat death of the universe . The program takes a list of space delimited integer arguments when called and sorts the list and comes in at 54 lines, but could definitely be shorter. import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.Random;public class Bogosort { public static void main(String[] args){ ArrayList<Integer> list = new ArrayList<Integer>(); for(String s : args){ list.add(Integer.parseInt(s)); } while(!isSorted(list)){ System.out.print("Unsorted list: "); print(list); shuffle(list); } System.out.print("Sorted list: "); print(list); } public static boolean isSorted(ArrayList<Integer> list){ int previous = list.get(0); for(int i = 1; i < list.size(); i++){ if(previous <= list.get(i)){ previous = list.get(i); } else { return false; } } return true; } public static void shuffle(ArrayList<Integer> list){ Collections.sort(list, new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { Random r = new Random(); return r.nextInt(2) - 1; } }); } public static void print(ArrayList<Integer> list){ for(int i = 0; i < list.size(); i++){ if(i < list.size() - 1) System.out.print(list.get(i) + ","); else System.out.print(list.get(i)); } System.out.println(); }}
  7. OEM license keys are generally different from the retail keys if I'm remembering correctly. Here's a post that explains the potential problem. http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_install/how-exactly-does-windows-7-retail-vs-oem/fae7b2ab-c530-45e6-aeb3-cc55cf7b9231?auth=1 But it's always worth a try. I've been able to do it before on an old Win7 laptop.
  8. I'm not too sure exactly what your problem is. I assume that it's not displaying what is being rendered on the second panel. If my understanding of your problem is correct, you have the JFrame, with a JPanel on it. That JPanel then has another JPanel contained within it. The second JPanel has no layout and nothing is being drawn to the screen when adding it in paintComponent(). If that is the case, here's a example I typed up to show you a potential issue. import java.awt.BorderLayout;import java.awt.Color;import java.awt.Graphics;import javax.swing.JFrame;import javax.swing.JPanel;public class GraphicsTest extends JFrame{ public GraphicsTest(){ JPanel container = new JPanel(); // the panel that contains the panel you are drawing to needs to have a // layout or the child panel will not render, comment out the line // below to see the problem in action container.setLayout(new BorderLayout()); container.add(new DrawablePanel(), BorderLayout.CENTER); this.add(container); // set up jFrame this.setSize(300, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setVisible(true); } public static void main(String[] args){ new GraphicsTest(); }}class DrawablePanel extends JPanel { @[member=OverRide] public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.BLACK); g.drawString("Test", 125, 125); }} The first panel, the one that contains the panel you are drawing to needs to have a layout for this to work. You can't nest two panels with no layout and attempt to paint to the second. I hope the code above is clear, but you're entirely right about using paintComponent. If I assumed incorrectly, what exactly is not working? Also, sorry for the verbose comments, lol. The example code is not the prettiest but hopefully it conveys the point.
  9. Depending on the difficulty of the project you're doing. You could always look at some computational intelligence stuff . Evolving the verilog code to solve a problem would be awesome.
  10. A few more things, if you're looking for a language to learn, I'd recommend C++ as your first. Most people advocate Python, but if you're going to go into depth with development and want to explore the underlying concepts, C++ won't hide the ugliness of computers from you, and it'll still give you access to Object Orientated stuff. I learnt it first and I think it definitely helped me grasp concepts in "easier" languages faster.
  11. As mentioned before it definitely depends on what exactly you're interested in doing. There are a lot of different concepts that all build on each other if you're interested in proper development. Learning a language is fine, but learning the underlying concepts is better IMHO. If you're interested in going into it fully I couldn't recommend a degree in IT, focussed on development, more. But in all honesty, most developers these days don't seem to have that and still do fine. If you're looking for the complete package, I'd say to have a look on https://www.google.com/about/careers/students/guide-to-technical-development.html. It's intended for people trying to improve their technical skills for Google, but they include links for a lot of free course material. Other than that, youtube is a great source of information, as well as Coursera, Udacity, and Udemy. Some of their stuff requires payment, but if I remember correctly, you can view the content for free. I may be mistaken though. There is also the aforementioned CodeAcademy. There is also Lynda.com, but you will definitely need to pay for that. As you get into development you can also have a look at http://www.codewars.com/ which is a site with real world challenges you can complete. They get quite tough, but they do improve your ability to problem solve. Hope that helps.
  12. It would be great to have one of these things. The small size with lower power consumption would be great, the performance doesn't seem too bad either. I'd be interested in using it as a steam streaming machine/steambox thing in the lounge. Or, my girlfriend is interested in getting into gaming and her current computer is still an old, loud and hot Core 2 Duo with onboard graphics. It'd be perfect for her as an upgrade to her current PC, not to mention it's her birthday in the next week so that would be even better. ;-)
×