import java.awt.*;import javax.swing.*;class Ua extends JFrame{public Ua(){setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(300,300);setLocation(100,100);setVisible(true);getContentPane().setBackground(Color.BLACK);}public void paint(Graphics g){g.setColor(Color.red);g.drawRect(100,100,120,100);}
2 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
import java.awt.*; import javax.swing.*; import java.awt.image.BufferedImage; class Ua extends JFrame { public Ua() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this .setSize( 300 , 300 ); this .setLocation( 100 , 100 ); this .setVisible( true ); } public void paint(Graphics g) { BufferedImage showImage = new BufferedImage( 300 , 300 ,BufferedImage.TYPE_BYTE_INDEXED); Graphics g2 = showImage.getGraphics(); Color c = g2.getColor(); g2.setColor(Color.GREEN); g2.fillRect( 0 , 0 , 300 , 300 ); g2.setColor(Color.red); g2.drawRect( 100 , 100 , 120 , 100 ); g2.setColor(c); g.drawImage(showImage, 0 , 0 , this ); } } public class Test { public static void main(String args[]) { new Ua(); } } |
添加回答
举报
0/150
提交
取消