1. #1
    High Overlord Nemean's Avatar
    10+ Year Old Account
    Join Date
    Jun 2010
    Location
    Auburn, Al
    Posts
    131

    Need some help making a GUI in java

    Hey guys, I'm working on a java project for fun, and I decided I want to make a GUI for it. Now I have had extremely little use of making a GUI with java. I have made a basic one a long time ago, but i dont quite remember everything. So just a basic understanding of what the program does. Its a grade book, you enter the desired file name, the amount of students, and the number of grades. Then it will ask for a student name and the grades for that student, after all student information is gathered, it will do some calculations and create a .dat and a .txt with the file name you gave earlier.
    CPU: Intel i5-2500k MB: ASRock Z77 Extreme
    GPU: Asus HD 7850 RAM: Mushkin Blackline 8GB
    HDD: WD Caviar Black 1TB PSU: OCZ 500W CASE: Cooler Master HAF 922

  2. #2
    The principle is that you have a JFrame in which you have panels and in those panels, you have components.
    Here is an extremely easy example: http://pastebin.com/unrFeA7V

    I can help you with specific things, just ask.
    I learned alot from this site: http://docs.oracle.com/javase/tutori...nts/index.html

  3. #3
    High Overlord Nemean's Avatar
    10+ Year Old Account
    Join Date
    Jun 2010
    Location
    Auburn, Al
    Posts
    131
    ok, so i made the frame and all, but how do i make the frame accept the data, then empty it once the data has been stored in the appropriate variables. And how do i make it close after so many times, ie. after all students have been gathered.
    CPU: Intel i5-2500k MB: ASRock Z77 Extreme
    GPU: Asus HD 7850 RAM: Mushkin Blackline 8GB
    HDD: WD Caviar Black 1TB PSU: OCZ 500W CASE: Cooler Master HAF 922

  4. #4
    Stood in the Fire Linaver's Avatar
    10+ Year Old Account
    Join Date
    Nov 2010
    Location
    Canada
    Posts
    426
    Any element on the frame can have an event associated with it, eg if you have a button on it it can have an on click event where you can put your method that would do whatever.

  5. #5
    High Overlord Nemean's Avatar
    10+ Year Old Account
    Join Date
    Jun 2010
    Location
    Auburn, Al
    Posts
    131
    also quick question, instead of making say 30 panels for grades is their a way i can just create them based on the number entered for grades.
    CPU: Intel i5-2500k MB: ASRock Z77 Extreme
    GPU: Asus HD 7850 RAM: Mushkin Blackline 8GB
    HDD: WD Caviar Black 1TB PSU: OCZ 500W CASE: Cooler Master HAF 922

  6. #6
    Ok, I accidently double posted, then deleted both of my posts, lol wtf?
    Anyway..

    Quote Originally Posted by Nemean View Post
    ok, so i made the frame and all, but how do i make the frame accept the data, then empty it once the data has been stored in the appropriate variables. And how do i make it close after so many times, ie. after all students have been gathered.
    From oracle.com: http://docs.oracle.com/javase/tutori...nlistener.html
    (http://docs.oracle.com/javase/tutori...omponents.html)

    Four examples on how you can handle actionlisteners:
    1. Anonymous class (most convenient in simple listeners, imo): http://pastebin.com/Fmc9Wfyz
    2. Implement the ActionListener-interface: http://pastebin.com/cfvneSiv
    3. Let the button class listen to itself: Main class -> http://pastebin.com/UmtyAYKd, Button class -> http://pastebin.com/0Z2MVCbv (I kept the button as a field because I forgot to change it back, but you get the idea)
    4. Nestled class: http://pastebin.com/J0FwJzYs

    If you want to know how to position your components, you should read up on LayoutManagers (http://docs.oracle.com/javase/tutori...ut/visual.html). You simply tell your panel what layout it should have and it'll position the component in the respective way.

    I hope it helped!

    Quote Originally Posted by Nemean View Post
    also quick question, instead of making say 30 panels for grades is their a way i can just create them based on the number entered for grades.
    If I understand you correctly, I would suggest you to look at solution number four in my previous post.

  7. #7
    If you want a more WYSIWYG feel you could just go download NetBeans or get the visual editor plugin for Eclipse. But there's still a learning curve and if you don't understand the basics you will probably get lost. I prefer WYSIWYG for GUI development because I hate having to specifically tell something which pixel is the start point and how many pixels to take up on the screen vs. just placing it there and moving it until it looks how I want it to look.

  8. #8
    Quote Originally Posted by tibben View Post
    If you want a more WYSIWYG feel you could just go download NetBeans or get the visual editor plugin for Eclipse. But there's still a learning curve and if you don't understand the basics you will probably get lost. I prefer WYSIWYG for GUI development because I hate having to specifically tell something which pixel is the start point and how many pixels to take up on the screen vs. just placing it there and moving it until it looks how I want it to look.
    This man states a valid point. =P
    (Even though I have never used one)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •