Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2011-01-19T12:48:20+00:00 → 2011-01-19T12:55:07+00:00
| − | Das ist Seite 2 |
| + | <language>Java</language> |
| + | <run id="4d36df2ae7e67"> |
| + | JButton myButton = new JButton("Button"); |
| + | JCheckBox myCheckBox = new JCheckBox("Check"); |
| + | JTextArea myText = new JTextArea("My text"); |
| + | JPanel bottomPanel = new JPanel(); |
| + | JPanel holdAll = new JPanel(); |
| − | Experimentieren Sie mit nachfolgendem Beispiel für Turtle Grafiken mit Java: |
| + | frame = new JFrame( "My Frame" ); |
| + | frame.setLocation(200, 200); |
| + | frame.setSize(300, 300); |
| − | <run> |
| − | canvas.clear(); // Zeichenfläche löschen |
| − | turtle.home(); |
| + | bottomPanel.setLayout(new FlowLayout()); |
| + | bottomPanel.add(myCheckBox); |
| + | bottomPanel.add(myButton); |
| + | |
| + | holdAll.setLayout(new BorderLayout()); |
| + | holdAll.add(bottomPanel, BorderLayout.SOUTH); |
| + | holdAll.add(myText, BorderLayout.CENTER); |
| + | |
| + | frame.getContentPane().add(holdAll, BorderLayout.CENTER); |
| + | frame.setVisible(true); |
| + | |
| + | myButton.addActionListener(this); |
| + | myCheckBox.addActionListener(this); |
| + | |
| + | void actionPerformed(ActionEvent e) |
| + | { |
| + | if (e.getSource() == myButton) |
| + | myText.setText("A button click"); |
| + | else if (e.getSource() == myCheckBox) |
| + | myText.setText("The checkbox state changed to " + |
| + | myCheckBox.isSelected()); |
| + | else |
| + | myText.setText("E ...?"); |
| + | } |
| − | boolean isUp = false; |
| − | |
| − | for(int i = 0; i < 18; i++){ |
| − | turtle.penColor(i*10+50,0,250-10*i); |
| − | turtle.penWidth(8); |
| − | turtle.forward(20); |
| − | turtle.right(20); |
| − | isUp = !isUp; |
| − | if(isUp) turtle.penUp(); else turtle.penDown(); |
| − | } |
</run> | |
| − | |
| − | <canvas></canvas> |
| − | |
| − | <run> |
| − | canvas.clear(); |
| − | Turtle t1 = new Turtle(1); |
| − | Turtle t2 = new Turtle(1); |
| − | t1.home(); |
| − | t2.home(); |
| − | t1.penColor(255,0,0); |
| − | t2.penColor(0,0,255); |
| − | t1.penWidth(2); |
| − | t2.penWidth(3); |
| − | |
| − | t1.left(90); |
| − | t1.forward(100); |
| − | t1.left(90); |
| − | t1.forward(20); |
| − | t2.forward(50); |
| − | |
| − | t1.setAngleTo(t2); |
| − | t2.setAngleTo(t1); |
| − | t1.forward(50); |
| − | t2.forward(50); |
| − | t1.hide(); |
| − | t2.hide(); |
| − | </run> |