2010年6月3日 星期四

期中考

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

public class TriangleMethod extends JFrame
implements ActionListener {

private JButton button;
private JPanel panel;
public static int a1,a2,b1,b2;
public static void main(String[] args)
{
a1 = Integer.parseInt(args[0]);
a2 = Integer.parseInt(args[1]);
b1 = Integer.parseInt(args[2]);
b2 = Integer.parseInt(args[3]);
TriangleMethod frame = new TriangleMethod();
frame.setSize(350, 300);
frame.createGUI();
frame.setVisible(true);
}

private void createGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new FlowLayout() );

panel = new JPanel();
panel.setPreferredSize(new Dimension(300, 200));
panel.setBackground(Color.white);
window.add(panel);

button = new JButton("Press me");
window.add(button);
button.addActionListener(this);
}

public void actionPerformed(ActionEvent event) {
Graphics paper = panel.getGraphics();
drawLogo(paper, 10, 20);
//drawLogo(paper, 100, 100);
//drawTriangle(paper, 100, 10, 40, 40);
drawTriangle(paper, 10, 100, a1, a2);
}

private void drawLogo(Graphics drawingArea,
int xPos, int yPos) {
drawingArea.drawRect(xPos, yPos, b1, b2);
//drawingArea.drawRect(xPos, yPos, 40, 40);
//drawingArea.drawRect(xPos, yPos, 20, 20);
}

private void drawTriangle(Graphics drawingArea,
int xPlace,
int yPlace,
int width,
int height) {
drawingArea.drawLine(xPlace, yPlace,

沒有留言:

張貼留言