E
ex-Ranger
Guest
im currently teaching myself Java and ive hit a roadblock i need a GUI for the program im writing. would any one happen to know where i can find a online tutorial for programing a GUI using eclipse
if you got any specific questions askI only know a bit, but I have used Eclipse when programming java, and made some GUI's
Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
how much do you know? (like, do you know how to use JFrame, JPane, different layoutl etc? )
if you are at the basics, start making one file that extends JFrame, and one that extends JPanel that you add to the one extending JFrame and remember to set the visibility and size of both.
import java.util.Scanner;
public class mainclass {
public static void main(String[] args) {
Scanner calendar = new Scanner(System.in);
System.out.println("open the calendar built into your computer and select for days in a square like 4 5 11 12 and add them together");
System.out.println("Enter sum of all four days:");
int sum = calendar.nextInt();
int day, day2, day3, day4, sum1;
sum1 = sum - 16;
day = sum1 / 4;
System.out.printf("first day is: ");
System.out.println(day );
day2 = day + 1;
System.out.printf("second day is: ");
System.out.println(day2 );
day3 = day + 7;
System.out.printf("third day is: ");
System.out.println(day3 );
day4 = day + 8;
System.out.printf("forth day is: ");
System.out.println(day4 );
}
}
for some reason the program I am trying to make will not run, and I cannot be bothered to find out why todaybut here is one class that might help, plus a modifications of your class:
-----
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class CalendarPanel extends JPanel {
public void CalendarPanel(){
JLabel instructions = new JLabel("open the calendar built into your computer and select for days in a square like 4 5 11 12 and add them together" +
"\n Enter sum of all four days ");
JTextField input = new JTextField();
add(input);
TestClass calculations = new TestClass();
calculations.calclulate();
// add metod to get results from calculations object
// and print theese to a graphical object
// for now you could use JLabels
int day = calculations.getDay();
JLabel firstday = new JLabel("Day 1" + day);
add(firstday);
}
}
--------
import java.util.Scanner;
public class TestClass {
//public static void main(String[] args) {
private int day, day2, day3, day4, sum1; // ALWAYS decalre variabeles private when possible
Scanner calendar;
public void TestClass(){
calendar = new Scanner(System.in);
}
public void calclulate(){
// System.out.println("open the calendar built into your computer and select for days in a square like 4 5 11 12 and add them together");
// System.out.println("Enter sum of all four days:");
int sum = calendar.nextInt();
sum1 = sum - 16;
day = sum1 / 4;
// Print to labels or elsewhere
System.out.printf("first day is: ");
System.out.println(day );
day2 = day + 1;
System.out.printf("second day is: ");
System.out.println(day2 );
day3 = day + 7;
System.out.printf("third day is: ");
System.out.println(day3 );
day4 = day + 8;
System.out.printf("forth day is: ");
System.out.println(day4 );
}
public int getDay(){ // Normally "getters" and "setters" are private
return day;
}
}
of course you will need to get the content from the input text area and send it to the calculations method
I'm still a rookie though, and I hate coding blind, so I cannot get any more accurate as long as my program will not run.