• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI  RSS feed

 
Lee Guarino
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone

i am new to this forum and am a relative begineer to java and am having a problem with creating my user interface. below is the code

public class GUI extends Frame implements ItemListener, ActionListener {


private TextField numOrders, lengthP, radiusP, quantityP;
private Choice gradeC, numColC;
private CheckboxGroup colours, chemical;
private Checkbox cYes, cNo, cInnerR, cOuterR, chemicalY, chemicalN;
private Button addPipe, calcCostP;

String stringIn;
int gradeIn;
boolean colourIn = false;
boolean innerRIn = false;
boolean outerRIn = false;
boolean chemicalRIn = false;
double lengthIn = 0.0;
double radiusIn = 0.0;
int ordersIn;
int quantityIn;

/** Creates a new instance of GUI */
public void init() {
Label lTitle, lNumOrd, lGrade, lNumC, coloursL, lRein, lLength, lRadius, lQuantity, lChemical;

setTitle("Pipe Ordering System");
setLayout(new FlowLayout());

lTitle = new Label("Welcome To Long Pipe Ordering System");
add(lTitle);

lGrade = new Label("Enter The Grade of Pipe");
add(lGrade);

gradeC = new Choice();
gradeC.add("1");
gradeC.add("2");
gradeC.add("3");
gradeC.add("4");
gradeC.add("5");
add(gradeC);
gradeC.addItemListener(this);

coloursL = new Label("Do you want colours?");
add(coloursL);

colours = new CheckboxGroup();
cYes = new Checkbox("Yes", colours, false);
add(cYes);
cYes.addItemListener(this);
cNo = new Checkbox("No", colours, false);
add(cNo);
cNo.addItemListener(this);

lNumC = new Label("Do you want colours?");
add(lNumC);

numColC = new Choice();
numColC.add("1");
numColC.add("2");
numColC.add("3");
add(numColC);
numColC.addItemListener(this);

lRein = new Label("Do you want reinforcements?");
add(lRein);

cInnerR = new Checkbox("Inner", false);
add(cInnerR);
cInnerR.addItemListener(this);

cOuterR = new Checkbox("Outer", false);
add(cOuterR);
cOuterR.addItemListener(this);

lChemical = new Label("Do you want chemical resistance?");
add(lChemical);

chemical = new CheckboxGroup();
chemicalY = new Checkbox("Yes", chemical, false);
add(chemicalY);
chemicalY.addItemListener(this);
chemicalN = new Checkbox("No", chemical, false);
add(chemicalN);
chemicalN.addItemListener(this);

lLength = new Label("Enter Length of Pipe");
add(lLength);

lengthP = new TextField(10);
add(lengthP);
lengthP.addActionListener(this);

lRadius = new Label("Enter the radius of pipe");
add(lRadius);

radiusP = new TextField(10);
add(radiusP);
radiusP.addActionListener(this);

addPipe = new Button("Create Pipe");
add(addPipe);
addPipe.addActionListener(this);

calcCostP = new Button("Calculate Cost");
add(calcCostP);
calcCostP.addActionListener(this);
}


public void itemStateChanged(ItemEvent e) {
}

public void actionPerformed(ActionEvent e) {
}

}


basically when i run the application the only thing that is displayed is "calcCostP" button. even when i comment out the code for it it still only displays this can anyone help?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

I'm moving this to our Swing forum for expert attention. (See link at top of page.)
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's your code modified - now displays it all (I think)
I removed all the listener stuff - not related to problem of display

even though it all displays, the layout is wrong - drag the window border
smaller/wider to see what happens

here's a link to the various layout managers
http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

finally, when posting code, use the code tags:
click the 'code' button, the tags will appear, paste your code between the tags

 
Lee Guarino
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah that works now thanks!
what layout would you suggest?
 
Lee Guarino
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also with the close that you added it has the error that
WindowAdapter is abstract and cannot be instantiated
how would i solve this
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> what layout would you suggest?

probably the easiest would be GridLayout(rows,columns)
where
rows = number of labels (8)
columns = 2 (left side for labels, right side for options)
note: the CheckBoxes will have to be added to a separate 'holding' panel,
and that panel added to the gridLayout panel

you add components to the gridLayout in this order left/right/left/right etc
i.e. rows are filled first.

this will give you a grid (8,2) - each grid will be the same size,
which should be OK for the labels, but the individual options (Choices,textfields etc)
might also have to be added to a holding panel, so you can control size/alignment

make a backup copy of your current code (working copy), and experiment with
a few layouts. Most times the desired effect is obtained via nesting panels
each using a different layout manager.

once you have the panel (minus buttons) OK, add this to contentPane.CENTER
the two buttons can be added to another panel, and this panel added to
contentPane.SOUTH

you can put the buttons in the gridlayout (rows = 9) if you wish,
but this generally looks odd


> WindowAdapter is abstract and cannot be instantiated
works fine for me - java 1.4.0_01
 
Lee Guarino
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool thanks for the help will try the grid layout and see how that works.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!