//好久不写swing的代码了
成都创新互联专业为企业提供聊城网站建设、聊城做网站、聊城网站设计、聊城网站制作等企业网站建设、网页设计与制作、聊城企业网站模板建站服务,十余年聊城做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
package swing;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JFrame;
import 搏态javax.swing.JPanel;
@SuppressWarnings("serial")
public class TestCanvas extends JFrame {
final Canvas canvas = new Canvas()
public TestCanvas() {
setTitle("DrawArcs");
add(canvas);
}
public static void main(String[] args) {
老衡 TestCanvas frame = new TestCanvas();
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
侍银做 class Canvas extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
Line2D.Double line = new Line2D.Double(0,0,300,300);
g2d.setColor(Color.RED);
g2d.draw(line);
int[] x = {50,200,350,300,100};
int[] y = {80,10,80,280,280};
Polygon polygon = new Polygon(x,y,5);
g2d.setColor(Color.GREEN);
g2d.drawPolygon(polygon);
Rectangle2D.Double rect = new Rectangle2D.Double(200,100,100,100);
g2d.setColor(Color.BLACK);
g2d.fill(rect);
}
}
}
1、importjava.util.Random;publicclassHello{publicstaticvoidmain(String[]args){/*doubler=Math.random();System.out.println(r);*/inti;Randomr=newRandom();i=r.nextInt(8);System.out.println(i);}
2、inti;Randomr=newRandom();i=r.nextInt(8);System.out.println(i);
3、publicstaticvoidmain(String[]args){inti;Randomr=newRandom();i=r.nextInt(8);System.out.println(i)。
4、publicclassHello{publicstaticvoidmain(String[]args)for(inti=1;i=4;i++)
for(intj=1;j=4-i;j++)System.out.print()。念亏
5、for(intk=1;k=2*i-1;k++)System.out.print(*);System.out.println()。
6、由于Java的诸多优点,java的发展前景十分广泛。ava可以参仔哪神与制作大部分网络应用程序系统,而且与如今流行的WWW浏览器结合很好,这一优点将促进Java的更大范围的缓州推广。