New Posts  All Forums:Forum Nav:

Need some java help

post #1 of 6
Thread Starter 
I cannot for the life of me figure out how to put 3 different user inputs into 3 different panels of a primary panel. Any help/guidance is appreciated!
post #2 of 6
i think what you need is a structure like this
Code:
JPanel parent = new JPanel(new FlowLayout());
JPanel child1 = new JPanel();
JPanel child2 = new JPanel();
JPanel child3 = new JPanel();

JTextField input1 = new JTextField();
JTextField input2 = new JTextField();
JTextField input3 = new JTextField();

child1.add(input1);
child2.add(input2);
child3.add(input3);

parent.add(child1);
parent.add(child2);
parent.add(child3);
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #3 of 6
Thread Starter 
Quote:
import java.awt.*;
import javax.swing.*;

public class Triathlon
{
public static void main (String[] args)
{

Triathlete one = new Triathlete ("Smith", "Andrea", 3605, 3600);
Triathlete two = new Triathlete();
Triathlete three = new Triathlete();

JFrame frame = new JFrame ("FiveK Run Display");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

JPanel subPanel1 = new JPanel();
subPanel1.setPreferredSize (new Dimension(300, 200));
subPanel1.setBackground(Color.green);
JLabel label1 = new JLabel();
subPanel1.add(label1);

JPanel subPanel2 = new JPanel();
subPanel2.setPreferredSize (new Dimension(300,200));
subPanel2.setBackground(Color.blue);
JLabel label2 = new JLabel();
subPanel1.add(label2);

JPanel subPanel3 = new JPanel();
subPanel3.setPreferredSize (new Dimension(300,200));
subPanel3.setBackground(Color.red);
JLabel label3 = new JLabel ();
subPanel1.add (label3);

JPanel primary = new JPanel();
primary.setBackground(Color.yellow);
primary.add (subPanel1);
primary.add (subPanel2);
primary.add (subPanel3);

frame.getContentPane().add(primary);
frame.pack();
frame.setVisible(true);


}
}
Quote:
import java.text.DecimalFormat;
import java.util.Scanner;


public class Triathlete
{
private String last;
private String first;
private int seconds;
private int personalRecord;
private double kph;

DecimalFormat dfmt = new DecimalFormat("0.##");
Scanner scan = new Scanner(System.in);



public Triathlete()
{

}

public Triathlete (String last, String first, int seconds, int personalRecord)
{
this.last = last;
this.first = first;
this.seconds = seconds;
this.personalRecord = personalRecord;

kph = 25.75 / (seconds / 3600d);


}

public String getLast()
{
return last;
}

public String getFirst()
{
return first;
}

public int getSeconds()
{
return seconds;
}

public int getPersonalRecord()
{
return personalRecord;
}

public double getKph()
{
return kph;
}

public void setLast(String last)
{
this.last = last;
}

public void setFirst(String first)
{
this.first = first;
}

public void setSeconds(int seconds)
{
this.seconds = seconds;
}

public void setPersonalRecord(int personalRecord)
{
this.personalRecord = personalRecord;
}

public void setKph(double kph)
{
this.kph = kph;
}

public String toString()
{
if (seconds == 0){
System.out.println("Enter last name: " );
String last = scan.next();
System.out.println("Enter first name: ");
String first = scan.next();
System.out.println("Enter seconds: ");
seconds = scan.nextInt();
System.out.println("Enter personal record: ");
personalRecord = scan.nextInt();

return "Name: " + last + ", " + first + "\
Time in seconds: " + seconds + "\
PR Time in seconds: "
+ personalRecord + "\
Average KM per hour: " + dfmt.format(25.75 / (seconds / 3600d))
+ "\
Average miles per hour: " + dfmt.format((25.75 / (seconds / 3600d)) * 0.621371192);
}

return "Name: " + last + ", " + first + "\
Time in seconds: " + seconds + "\
PR Time in seconds: "
+ personalRecord + "\
Average KM per hour: " + dfmt.format(kph) + "\
Average miles per hour: "
+ dfmt.format((25.75 / (seconds / 3600d)) * 0.621371192);

}




}

I have to get three objects from Triathlete into separate panels. I have the panels set up and as you can see my one object has specific parameters while the others accept input. How can I get each object into it's own subpanel?
post #4 of 6
Thread Starter 
I could seriously use some help!
post #5 of 6
to gather input for the other 2 triathletes you can put text fields in the subpanels. then get the info from the text fields and pass it onto the constructor for triathlete.

on submit button click:
Triathlete one = new Triathlete (textfield1.getText(), textfield2.getText(), ...);
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #6 of 6
Quote:
Originally Posted by JCarney View Post
I could seriously use some help!
Why don't you just come out and say you want someone to do it? He gave you more than enough information to go off of. Also, if you want anyone to bother looking at your code, consider placing
Code:
 and
tags around it.
Primary PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II 720 (2.8 ghz) BIOSTAR A780L3L (AM3) MSI GeForce 9800GT G.Skill Ripjaws Series DDR3 1600 (8GB) 
Hard DriveOSMonitorPower
Crucial M4 64GB / Samsung F3 1TB Windows 7 Pro (64-bit) Dell SP2309W (2048x1152) PC Power & Cooling 610W 
CaseMouse
Cooler Master Elite 430 RC Logitech MX518 
  hide details  
Reply
Primary PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II 720 (2.8 ghz) BIOSTAR A780L3L (AM3) MSI GeForce 9800GT G.Skill Ripjaws Series DDR3 1600 (8GB) 
Hard DriveOSMonitorPower
Crucial M4 64GB / Samsung F3 1TB Windows 7 Pro (64-bit) Dell SP2309W (2048x1152) PC Power & Cooling 610W 
CaseMouse
Cooler Master Elite 430 RC Logitech MX518 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming