Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Pre-Quiz 3-Spring 2007 Questions

Q2. What is the major difference between Stacks and Queues with respect to how elements are added and removed from each?

Stacks - FILO (first in last out)
Queue - FIFO (first in first out)

Question: What is a GUI tree? can you ellaborate please?

Q3. What is the difference between a FlowLayout, GridLayout, and BorderLayout?
Q4B)
Is there a better way to do this?
(the name is changed to PreQuiz3GUIAnswer instead of StringReverseGUI)

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

public class PreQuiz3GUIAnswer extends JFrame{
  
  JTextField txtInput;
  String rvrseTxt = "";
  JLabel display;
  
  public PreQuiz3GUIAnswer(){
    setLayout (new BorderLayout());
    
    txtInput = new JTextField("Type Something Here");
    JButton button1 = new JButton("Forward");
    display = new JLabel("");
    
    button1.addActionREMOVEDstener(new ActionREMOVEDstener(){
      public void actionPerformed(ActionEvent ae){
        display.setText(txtInput.getText());
      }
    });
    
    JButton button2 = new JButton("Reversed");
    button2.addActionREMOVEDstener(new ActionREMOVEDstener(){
      public void actionPerformed(ActionEvent ae){
        for (int i=0; i<txtInput.getText().length(); i++) {
          rvrseTxt = txtInput.getText().substring(i, i+1) + rvrseTxt;
            }
        display.setText(rvrseTxt);
        rvrseTxt = "";
      }
    });
    
    add(txtInput, BorderLayout.NORTH);
    add(button1, BorderLayout.WEST);
    add(button2, BorderLayout.EAST);
    add(display, BorderLayout.SOUTH);
    
    this.pack();
    this.setVisible(true);
  }
  
  public static void main(String[]args){
    PreQuiz3GUIAnswer prequiz = new PreQuiz3GUIAnswer();
  }
}




Link to this Page