UICS20

UICS20 - if(e.getSource == buttons[0 Build button String exp_str = text1.getText exp = new Expression(exp_str for(int i=1 i< BSIZE i

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * CS20S08 PA2 * Esra * User Interface */ import java.awt.*; import java.awt.event.*; public class UICS20 extends Frame implements WindowListener,ActionListener { final int BSIZE=4; final int TSIZE=100; TextField text1 = new TextField( "Type the expression here", TSIZE); TextField text2 = new TextField(TSIZE); Button [] buttons = new Button[BSIZE]; Expression exp; public static void main(String[] args) { UICS20 myWindow = new UICS20("UI for cs20 Assignment 2"); myWindow.setSize(900,250); myWindow.setVisible(true); } public UICS20(String title) { super(title); setLayout(new FlowLayout()); addWindowListener(this); buttons[0] = new Button("Build"); buttons[1] = new Button("Infix"); buttons[2] = new Button("Prefix"); buttons[3] = new Button("Postfix"); for(int i=0; i< BSIZE; i++){ add(buttons[i]); buttons[i].addActionListener(this); } for(int i=1; i< BSIZE; i++) buttons[i].setEnabled(false); add(text1); add(text2); } public void actionPerformed(ActionEvent e) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (e.getSource() == buttons[0]){// Build button String exp_str = text1.getText(); exp = new Expression(exp_str); for(int i=1; i< BSIZE; i++) buttons[i].setEnabled(true); } else if (e.getSource() == buttons[1]){// Infix button String str_in = exp.infixString(); text2.setText(str_in); } else if (e.getSource() == buttons[2]){// Prefix button String str_pre = exp.prefixString(); text2.setText(str_pre); } else if (e.getSource() == buttons[3]){// Postfix button String str_post = exp.postfixString(); text2.setText(str_post); } } public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } public void windowOpened(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} }...
View Full Document

This note was uploaded on 10/02/2009 for the course CS 20 taught by Professor Agrawal during the Spring '08 term at UCSB.

Page1 / 2

UICS20 - if(e.getSource == buttons[0 Build button String exp_str = text1.getText exp = new Expression(exp_str for(int i=1 i< BSIZE i

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online