Script Java

Script Java Script Java

29.01.2014 Aufrufe

11.4 Stack public class Left extends Command { private int argument; public Left(int n) {argument = n;} public void run() {turtle.right(-argument);} public String toString() {return "left "+argument+"\n";} } public class Sequence extends Command { private Stack commands; public Sequence() {commands = new Stack();} public void add(Command c) {commands.push(c);} public void undo() {if (!commands.empty()) commands.pop();} public void run() { int size = commands.size(); for (int i=0;i

11.4 Stack public NumCheckbox(int n, boolean state, CheckboxGroup group) { super(String.valueOf(n),state,group); num = n; } } public int getNum() {return num;} public class Drawing extends Frame { public Drawing() { setTitle("Drawing"); setBounds(400,0,400,500); setVisible(true); } } public void paint(Graphics g) {logo.run(g);} private void place(Component comp,int x,int y,int width,int height) { comp.setBounds(x, y, width, height); add(comp); } public UserFrame() { setTitle("Editor"); setLayout(null); setBounds(0,0,400,515); setResizable(false); commands = new CheckboxGroup(); arguments = new CheckboxGroup(); place(text = new TextArea(),30,80,340,340); text.setBackground(Color.white); place(button = new Button("CLEAR"),30,450,60,20); button.setBackground(Color.white); button.addActionListener(this); place(new Checkbox("FD",true,commands),120,440,40,15); place(new Checkbox("BK",false,commands),120,455,40,15); place(new Checkbox("RT",false,commands),120,470,40,15); place(new Checkbox("LT",false,commands),120,485,40,15); place(new NumCheckbox(5,true,arguments),170,440,40,15); place(new NumCheckbox(30,false,arguments),170,455,40,15); place(new NumCheckbox(50,false,arguments),170,470,40,15); place(new NumCheckbox(90,false,arguments),170,485,40,15); place(button = new Button("DO"),240,450,60,20); button.setBackground(Color.white); button.addActionListener(this); place(button = new Button("UNDO"),310,450,60,20); button.setBackground(Color.white); button.addActionListener(this); logo = new Logo(); drawing = new Drawing(); setVisible(true); } public void actionPerformed(ActionEvent event) { if (event.getActionCommand().equals("CLEAR")) { logo.clear(); 241

11.4 Stack<br />

public NumCheckbox(int n, boolean state, CheckboxGroup group) {<br />

super(String.valueOf(n),state,group);<br />

num = n;<br />

}<br />

}<br />

public int getNum() {return num;}<br />

public class Drawing extends Frame {<br />

public Drawing() {<br />

setTitle("Drawing");<br />

setBounds(400,0,400,500);<br />

setVisible(true);<br />

}<br />

}<br />

public void paint(Graphics g) {logo.run(g);}<br />

private void place(Component comp,int x,int y,int width,int height) {<br />

comp.setBounds(x, y, width, height);<br />

add(comp);<br />

}<br />

public UserFrame() {<br />

setTitle("Editor");<br />

setLayout(null);<br />

setBounds(0,0,400,515);<br />

setResizable(false);<br />

commands = new CheckboxGroup();<br />

arguments = new CheckboxGroup();<br />

place(text = new TextArea(),30,80,340,340);<br />

text.setBackground(Color.white);<br />

place(button = new Button("CLEAR"),30,450,60,20);<br />

button.setBackground(Color.white);<br />

button.addActionListener(this);<br />

place(new Checkbox("FD",true,commands),120,440,40,15);<br />

place(new Checkbox("BK",false,commands),120,455,40,15);<br />

place(new Checkbox("RT",false,commands),120,470,40,15);<br />

place(new Checkbox("LT",false,commands),120,485,40,15);<br />

place(new NumCheckbox(5,true,arguments),170,440,40,15);<br />

place(new NumCheckbox(30,false,arguments),170,455,40,15);<br />

place(new NumCheckbox(50,false,arguments),170,470,40,15);<br />

place(new NumCheckbox(90,false,arguments),170,485,40,15);<br />

place(button = new Button("DO"),240,450,60,20);<br />

button.setBackground(Color.white);<br />

button.addActionListener(this);<br />

place(button = new Button("UNDO"),310,450,60,20);<br />

button.setBackground(Color.white);<br />

button.addActionListener(this);<br />

logo = new Logo();<br />

drawing = new Drawing();<br />

setVisible(true);<br />

}<br />

public void actionPerformed(ActionEvent event) {<br />

if (event.getActionCommand().equals("CLEAR")) {<br />

logo.clear();<br />

241

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!