?? exercise11_4.java
字號:
import java.awt.*;
import javax.swing.*;
public class Exercise11_4 extends JFrame {
public Exercise11_4() {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new DrawXSquare(), BorderLayout.CENTER);
}
public static void main(String[] args) {
Exercise11_4 frame = new Exercise11_4();
frame.setSize(400, 400);
frame.setTitle("Exercise11_4");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
class DrawXSquare extends JPanel {
double f(double x) {
return x*x;
}
public void drawFunction() {
repaint();
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(10, 200, 390, 200);
g.drawLine(200, 30, 200, 390);
g.drawLine(390, 200, 370, 190);
g.drawLine(390, 200, 370, 210);
g.drawLine(200, 30, 190, 50);
g.drawLine(200, 30, 210, 50);
g.drawString("X", 390, 170);
g.drawString("Y", 220, 40);
Polygon p = new Polygon();
double scaleFactor = 0.01;
for (int x = -100; x <= 100; x++) {
p.addPoint(x + 200, 200 - (int)(scaleFactor * f(x)));
}
g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -