2个回答
展开全部
/**
* @作者 王建明
* @创建日期 2013-07-15
* @创建时间 14:25:59
* @版本号 V 1.0
*/
public class CosTest {
/**
* 画出y=cos(x)的图;<br>
*
* x取[0~2*pai],扩大10倍为[0,62];<br>
* y的范围是[-1,1],扩大10倍为[-10,10]
*/
public static void main(String[] args) {
int x = 0;
int y = 10;
/*
* 加减乘除都使用int整数类型; acos的参数依然是[-1,1]的double类型
*/
for (; y >= -10; y -= 1) {// y取[-10,10]
x = (int) (Math.acos(y / 10.0) * 10);
for (int i = 0; i <= 62; i++) {
if (i == x || i == 62 - x) {// x取[0,62]
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package ui;import java.awt.*;import javax.swing.*;import java.util.*;class MyPanel extends JPanel { private Vector<JComponent> comps; public MyPanel () { comps = new Vector<JComponent>(); setLayout(null); } public void paint (Graphics g) { g.setColor(Color.BLACK); for (int i=1; i<comps.size(); i++) { g.drawLine(comps.get(0).getLocation().x+comps.get(0).getSize().width/2, comps.get(0).getLocation().y+comps.get(0).getSize().height/2, comps.get(i).getLocation().x+comps.get(i).getSize().width/2, comps.get(i).getLocation().y+comps.get(i).getSize().height/2); } super.paintComponents(g); } public void addComponent (JComponent comp) { comp.setOpaque(true); comps.add(comp); add(comp); repaint(); }}public class MyFrame extends JFrame { private MyPanel mp; public MyFrame () { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mp = new MyPanel(); setContentPane(mp); } public void addComponent (JComponent comp) { mp.addComponent(comp); }}---------------------------- TestMyFrame.java -----------------------------import ui.*;import javax.swing.*;import javax.swing.border.*;public class TestMyFrame { public static void main (String args[]) { MyFrame mf = new MyFrame(); mf.setSize(500, 500); mf.setLocationRelativeTo(null); mf.setVisible(true); testAddComponent(mf); } public static void testAddComponent (MyFrame mf) { JLabel l1 = new JLabel("l1"); l1.setBorder(new EtchedBorder()); l1.setBounds(200, 100, 20, 20); mf.addComponent(l1); JLabel l2 = new JLabel("l2"); l2.setBounds(100, 150, 20, 20); l2.setBorder(new EtchedBorder()); mf.addComponent(l2); JLabel l3 = new JLabel("l3"); l3.setBounds(150, 150, 20, 20); l3.setBorder(new EtchedBorder()); mf.addComponent(l3); JLabel l4 = new JLabel("l4"); l4.setBounds(200, 150, 20, 20); l4.setBorder(new EtchedBorder()); mf.addComponent(l4); }}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询