Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Jared Upton

Greenhorn
+ Follow
since Apr 07, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jared Upton

This is how I delclared it above for the GUI


// Variables declaration
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JLabel jLabel7;
private JLabel jLabel8;
private JTextField jTextField1;
private JTextField jTextField2;
private JTextField jTextField3;
private JTextField jTextField4;
private JTextField jTextField5;
private JTextField jTextField6;
private JTextField jTextField7;
12 years ago
nm thanks I figured this part of it out
[ April 26, 2006: Message edited by: Jared Upton ]
12 years ago
With box how do I add empty lines or space the stuff say one TABs length? I add spaces to the " this is My label" but it never spaces it over.
I had to add a label with "_____________" just to get the buttons spaced far enough apart.
12 years ago
Okay this is going to be more difficult then I thought. I created it in a grid layout but how do I tell each label which cell in the Grid for it to be in?


import javax.swing.*;
import java.awt.*;

public class GUI {

public static void main (String[] args){
GUI process = new GUI();
process.makeGUI();


}

public void makeGUI() {

JFrame frame = new JFrame();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel(new GridLayout(0,2));
panel1.setBackground(Color.darkGray);
panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));

panel1.add(new JButton("Process Order"));
panel1.add(new JLabel("___________________________________________"));
panel1.add(new JButton("Deliver"));
panel2.add(new JLabel("Regular",JLabel.CENTER));
panel2.add(new JLabel("Spoilable"));
panel2.add(new JLabel("Total Weight"));
panel2.add(new JLabel("test"));
panel2.add(new JLabel("Total Length"));
panel2.add(new JLabel("test"));
panel2.add(new JLabel("Total Number of Trucks Needed"));
panel2.add(new JLabel("Semis"));
panel2.add(new JLabel("test"));
panel2.add(new JLabel("Refrig"));
panel2.add(new JLabel("test"));
frame.getContentPane().add(BorderLayout.SOUTH, panel1);
frame.getContentPane().add(BorderLayout.NORTH, panel2);
frame.setSize(500,500);
frame.setVisible(true);





}
}
12 years ago
I am making a gui but not sure how to place my text labels where i want them.I want it to something look like this but no idea how to move my labels. Like with the buttons i used a _ symbol in a label to space them apart.

Spoilable Regular
Total Weight
Total Length


Number of Trucks Needed
Semi
Refrig

Button Button




import javax.swing.*;
import java.awt.*;


public class GUI {

public static void main (String[] args){
GUI process = new GUI();
process.makeGUI();


}

public void makeGUI() {

JButton process = new JButton("Process Order");
JButton deliver = new JButton("Deliver");


JLabel southspace = new JLabel("___________________________________________");
JLabel label1 = new JLabel("Regular");
JLabel label2 = new JLabel("Spoilable");
JLabel label3 = new JLabel("Total Weight");
JLabel label4 = new JLabel("test");
JLabel label5 = new JLabel("Total Length");
JLabel label6 = new JLabel("test");
JLabel label7 = new JLabel("Total Number of Trucks Needed");
JLabel label8 = new JLabel("Semis");
JLabel label9 = new JLabel("test");
JLabel label10 = new JLabel("Refrig");
JLabel label11 = new JLabel("test");


JFrame frame = new JFrame();
JPanel panelS = new JPanel();
JPanel panelC = new JPanel();
panelS.setBackground(Color.darkGray);
panelS.setLayout(new BoxLayout(panelS, BoxLayout.X_AXIS));
panelC.setLayout(new BoxLayout(panelC, BoxLayout.X_AXIS));

panelS.add(process);
panelS.add(southspace);
panelS.add(deliver);
panelC.add(label1);
panelC.add(label2);
panelC.add(label3);
panelC.add(label4);
frame.getContentPane().add(BorderLayout.SOUTH, panelS);
frame.getContentPane().add(BorderLayout.NORTH, panelC);
frame.setSize(500,500);
frame.setVisible(true);

}
}
12 years ago
I used netbeans to build a GUI but when i try to compile the .java code in Textpad to test it I get an error. Sorry If this is a stupid question I am new to GUI and trying to find an easier way to do it.


/*
* TeamProjext.java
*
* Created on April 19, 2006, 10:56 PM
*/

/**
*
* @author Jarod
*/
public class TeamGUI extends javax.swing.JFrame {

/** Creates new form TeamProjext */
public TeamGUI() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Process Order");

jButton2.setText("Deliver");

jLabel3.setText("Total Trucks needed");

jLabel4.setText("Regular");

jLabel5.setText("Refrigerated");

jLabel6.setText("Total Weight");

jLabel7.setText("Total Length");

jLabel8.setText("Spoilable");

jLabel9.setText("Regular");

jLabel1.setText("jLabel1");

jLabel2.setText("jLabel2");

jLabel10.setText("jLabel10");

jLabel11.setText("jLabel11");

jLabel12.setText("jLabel12");

jLabel13.setText("jLabel13");

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(106, 106, 106)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 77, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel4))
.add(62, 62, 62)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel12)
.add(jLabel13))
.addContainerGap(139, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel8)
.add(jLabel9))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 55, Short.MAX_VALUE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel3)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel6)
.add(jLabel1)
.add(jLabel2))
.add(85, 85, 85)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel11)
.add(jLabel10)
.add(jLabel7))))
.add(83, 83, 83))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel6)
.add(jLabel7))
.add(16, 16, 16)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel8)
.add(jLabel1)
.add(jLabel10))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel9)
.add(jLabel2)
.add(jLabel11))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 47, Short.MAX_VALUE)
.add(jLabel3)
.add(16, 16, 16)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel4)
.add(jLabel12))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel5)
.add(jLabel13))
.add(32, 32, 32))
);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.add(layout.createSequentialGroup()
.add(30, 30, 30)
.add(jButton1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 156, Short.MAX_VALUE)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 113, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(26, 26, 26))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton1)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(30, 30, 30))
);
pack();
}// </editor-fold>//GEN-END:initComponents

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TeamGUI().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
// End of variables declaration//GEN-END:variables

}
[ April 19, 2006: Message edited by: Jared Upton ]
12 years ago
Okay i got the thing to compile but it is not printing out the
System.out.println("Rat:" + ratscore);





import java.util.*; // for the Scanner class
import java.io.*; // for the File class


public class calc {

public static void main (String[] args)
{
calc mygrade = new calc();
mygrade.readgrades();
}


public void readgrades() {
double[] scores = new double[7];
double ratscore = 0.0;
double programscore = 0.0;
double examscore = 0.0;
double teamratscore = 0.0;
double teamXMLscore = 0.0;
double teamexamscore = 0.0;
double peerevalscore = 0.0;
double linedouble = 0.0;

try {
File grades = new File("grades.txt");
FileReader fr = new FileReader(grades);
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
for (int i = 0; i < 7; i++) {
scores[i] = Double.parseDouble(line);
line = br.readLine();
}
br.close();
} catch(Exception ex) {
ex.printStackTrace();


ratscore = scores[0];
programscore = scores[1];
examscore = scores[2];
teamratscore = scores[3];
teamXMLscore = scores[4];
teamexamscore = scores[5];
peerevalscore = scores[6];
System.out.println("Rat:" + ratscore);

}



}
}
12 years ago
Yeh I plan on using the readLine to call the information in the BufferedReader.
How should I define it?
[ April 14, 2006: Message edited by: Jared Upton ]
12 years ago
import java.util.*; // for the Scanner class
import java.io.*; // for the File class


public class gradecalc {

double[] grades = new double[7];

public void readgrades() {
try {
File grades = new File("grades.txt");
FileReader fr = new FileReader(grades);
BufferedReader br = new BufferedReader(fr);
} catch(Exception ex) {
ex.printStackTrace();
}
}






public void parsefile() {

double ratscore = 0.0;
double programscore = 0.0;
double examscore = 0.0;
double teamratscore = 0.0;
double teamXMLscore = 0.0;
double teamexamscore = 0.0;
double peerevalscore = 0.0;
double s = 0.0;

for (int i = 0; i < grades.length; i++) {
readLine(s);
double value = Double.parseDouble(s);
grades[i] = readLine(s);

}
}

public static void main() {
readgrades();
parsefile();



} //Main
}// cla
12 years ago
I am still lost on how to exactly use the Double.parseDouble command and how to get it to read each line and assign it to the array. Here is what I got so far. Any I code I could look at for ideas or help would be appreciated. I am having such a hard time grasping this object oriented language.

import java.util.*; // for the Scanner class
import java.io.*; // for the File class


public class gradecalc {

double[] grades = new double[6];

public void readgrades() {
try {
File getty = new File("grades.txt");
FileReader fr = new FileReader(grades);
BufferedReader br = new BufferedReader(fr);
} catch(Exception ex) {
ex.printStackTrace();
}







public void parseFile() {

double ratscore = 0.0;
double programscore = 0.0;
double examscore = 0.0;
double teamratscore = 0.0;
double teamXMLscore = 0.0;
double teamexamscore = 0.0;
double peerevalscore = 0.0;


for (int i = 0; i < grades.length; i++) {
double[i] grades = new double[i];
[ April 14, 2006: Message edited by: Jared Upton ]
12 years ago
I need to parse a text file grades.txt and pull numbers from it to calculate my grade. The grades.txt file will look like this also my current code is below it albeit still a bit rough. Just trying to pulling the info from the file at this point then I will worry about calculating the grade. So any sample code I could look at to see how it is done would be appreciated.





50
80
99
40
85
98
76











import java.util.*; // for the Scanner class
import java.io.*; // for the File class


public class gradecalc {


public void grades() {
try{
File grades = new File("grades.txt");
fileReader = new FileReader(grades);
BufferedReader = new BufferedReader();
} catch(Exception ex) {
ex.printStackTrace();
}
}


public void parseFile() {

try {
// Temporary variables to hold individual field values for a record
double ratscore = 0.0;
double programscore = 0.0;
double examscore = 0.0;
double teamratscore = 0.0;
double teamXMLscore = 0.0;
double teamexamscore = 0.0;
double peerevalscore = 0.0;
[ April 14, 2006: Message edited by: Jared Upton ]
12 years ago
I have to write a program for class to calculate days old based on your birth date. I am kinda lost in the class and would appreciate any help. Trying to figure out how i would do the math to account for leap years different amount of days in months etc..
12 years ago
I haven't even started all I have done is look at some other examples. This may be a bit above my head but it seems interesting. I was thinking of using an arraylist. But still trying to figure out how to work with a 9 by 9 grid and figure out how to get the answer by brute force.
12 years ago
I need to create a program for class to either create a suduko or to solve one.
I leaning towards creating them since it seems easier any help would be appreciated. I am still new to this language so be gentle
12 years ago