안녕하세요! 나는이 문제를 안고있다 : 인간의 형상을 디자인하는 자바 프로그램을 만들어야 만한다. 나는 인간을 디자인하는 코드를 작성했지만 색상을 사용하여 도형을 채우는 방법을 모른다. "java.awt.Color"를 사용해야한다는 것을 알고 있지만 어떻게 사용하는지 모른다.자바에서 디자인의 색상을 지정하려면 어떻게해야합니까?
색상은 이미지의 배경 (노란색), 머리 (파란색), 암 & 다리 (녹색), 몸 (빨간색)이어야합니다. 여기
지금까지 내 코드입니다 :import javax.swing.*;
import java.awt.*;
public class DrawPanelTest {
//creates a window to display the drawing
public static void main(String[] args) {
// create a new frame to hold the panel
JFrame application = new JFrame();
Container pane=application.getContentPane();
// create a panel that contains our drawing
DrawPanel panel = new DrawPanel();
// set the frame to exit when it is closed
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// add the panel to the frame
pane.add(panel);
application.setContentPane(pane);
// set the size of the frame
application.setSize(550, 450);
// make the frame visible
application.setVisible(true);
}
}
그리고 여기에 그림이 그려지는 곳입니다 :
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawPanel extends JPanel {
public void paintComponent(Graphics g) {
//draw the human
g.drawOval(300, 100, 100, 100);
g.drawRect(300, 200, 100, 100);
g.drawRect(400,200, 100, 10);
g.drawRect(200,200, 100, 10);
g.drawRect(300,300, 10, 100);
g.drawRect(390,300, 10, 100);
}
}
감사합니다. 나는 어떻게 보이게 만드는지 몰랐습니다. – MKB
문제가 없으므로 "{}"버튼을 클릭하여 텍스트의 선택을 코드 –