「color坐标java」xyz坐标颜色
今天给各位分享color坐标java的知识,其中也会对xyz坐标颜色进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、用JAVA用Graphics2D来绘制一个坐标系,带刻度的那种
- 2、java编程实现编写一个图形用户界面实现多边形面积计算要求建立坐标系输入多边形顶点数输出结果
- 3、java color 赋值
- 4、java中color 类的常见作用作用
- 5、java中如何从Color属性字符串中获取颜色Color
用JAVA用Graphics2D来绘制一个坐标系,带刻度的那种
public class test8888 extends JPanel
{
Polygon po = new Polygon();
Font fn = new Font("宋体", Font.BOLD, 22);
Font fn2 = new Font("宋体", Font.BOLD, 20);
int x = 100;
int y = 100;
int[] pox ={ 90, 100, 100 };
int[] poy ={ 110, 90, 100 };
int[] poxx ={ 100, 100, 110 };
int[] poyy ={ 90, 90, 110 };
int[] poxB = {687,697,707};
int[] poyB = {690,700,700};
int[] poxBB = {687,697,707};
int[] poyBB = {710,700,700};
public test8888()
{
setSize(900, 900);
}
public void paint(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.black);
g2d.fillRect(99, 100, 2, 600);
g2d.fillRect(99, 700, 600, 2);
g2d.fillRect(100, 685, 15, 15);
for (int i = 0; i 37; i++)
{
g2d.drawLine(100 + i * 15, 600 + y, y + i * 15, y + 45);
g2d.drawLine(100, 600 + y - i * 15, y + 555, y + 600 - i * 15);
g2d.drawString("0", x - 20, 720);
if (i % 2 == 0 i / 2 != 0)
{
g2d.drawString(String.valueOf(i / 2), x - 20, 705 - i / 2 * 30);
g2d.drawString(String.valueOf(i / 2), x - 5 + i / 2 * 30, 720);
}
}
g2d.setFont(fn2);
g2d.setColor(Color.white);
g2d.drawString("A", 102, 700);
g2d.setFont(fn);
g2d.setColor(Color.black);
g2d.drawString("Y", 80, 140);
g2d.drawString("X", 670, 720);
g2d.fillPolygon(pox,poy,3);
g2d.fillPolygon(poxx,poyy,3);
g2d.fillPolygon(poxB,poyB,3);
g2d.fillPolygon(poxBB,poyBB,3);
g2d.dispose();
}
public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setSize(900, 900);
jf.setVisible(true);
jf.setDefaultCloseOperation(3);
jf.getContentPane().add(new test8888());
}
}
java编程实现编写一个图形用户界面实现多边形面积计算要求建立坐标系输入多边形顶点数输出结果
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class CalculateArea extends JFrame {
private static final long serialVersionUID = 8109685421829572012L;
private JTextField cntField;
private JPanel panel;
private JScrollPane sPanel;
private JTextField[][] coordinateFields;
private JTextField resultField ;
public CalculateArea(String title){
super(title);
init();
}
public void init(){
Container c = this.getContentPane();
JPanel panel1 = new JPanel();
panel1.setPreferredSize(new Dimension(260, 30));
panel1.setLayout(new FlowLayout());
JLabel cntLab = new JLabel("多边形边数:");
cntLab.setPreferredSize(new Dimension( 70, 20));
panel1.add(cntLab);
cntField = new JTextField();
cntField.setPreferredSize(new Dimension(110, 20));
panel1.add(cntField);
JButton okBut = new JButton("确定");
okBut.setPreferredSize(new Dimension( 60, 20));
okBut.addActionListener(new CreatePanelActionListener(this));
panel1.add(okBut);
c.add(panel1,BorderLayout.NORTH);
//给确定按钮添加自定义事件
panel = new JPanel();
sPanel = new JScrollPane();
sPanel.setPreferredSize(new Dimension(240, 300));
sPanel.setViewportView(panel);
sPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
c.add(sPanel, BorderLayout.CENTER);
JPanel panel2 = new JPanel();
panel2.setPreferredSize(new Dimension(260, 30));
panel2.setLayout(new FlowLayout());
JButton calculateBut = new JButton("计算");
calculateBut.setPreferredSize(new Dimension( 60, 20));
panel2.add(calculateBut);
JLabel resultLab = new JLabel("计算结果为:");
resultLab.setPreferredSize(new Dimension( 70, 20));
panel2.add(resultLab);
resultField = new JTextField();
resultField.setPreferredSize(new Dimension(110, 20));
panel2.add(resultField);
calculateBut.addActionListener(new CalculateActionListener(this));
c.add(panel2,BorderLayout.SOUTH);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
System.exit(0);
}
});
// this.setResizable(false);
this.setSize(300, 500);
setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args) {
new CalculateArea("多边形面积计算");
}
public JTextField getCntField() {
return cntField;
}
public JPanel getPanel() {
return panel;
}
public JTextField[][] getCoordinateFields() {
return coordinateFields;
}
public void setCoordinateFields(JTextField[][] coordinateFields) {
this.coordinateFields = coordinateFields;
}
public JScrollPane getsPanel() {
return sPanel;
}
public JTextField getResultField() {
return resultField;
}
}
//计算面积的事件
class CalculateActionListener implements ActionListener{
private JFrame frame;
public CalculateActionListener(JFrame frame){
this.frame = frame;
}
public void actionPerformed(ActionEvent e) {
JPanel panel = ((CalculateArea)frame).getPanel();
JTextField[][] coordinateFields = ((CalculateArea)frame).getCoordinateFields();
JTextField resultField = ((CalculateArea)frame).getResultField();
int[][] coord = new int[2][coordinateFields[0].length];
if(coordinateFields==null){
JLabel label = new JLabel("请先输入多边形,然后填写坐标信息!");
label.setBounds(40, 200, 295, 20);
panel.add(label);
frame.repaint();
}else{
for (int i = 0; i coordinateFields[0].length; i++) {
try{
String xStr = coordinateFields[0][i].getText();
String yStr =coordinateFields[1][i].getText();
int x = Integer.parseInt(xStr);
int y = Integer.parseInt(yStr);
coord[0][i] = x;
coord[1][i] = y;
}catch (Exception ex) {
resultField.setText("输入的坐标值有误,请修改后重新输入!");
frame.repaint();
return;
}
}
calulateArea(coord, resultField);
}
}
//根据坐标计算面积
//计算多边形面积公式为:0.5*abs(x1*y2-y1*x2+x2*y3-y2*x3+...+xn*y1-yn*x1)
public void calulateArea(int[][] coord,JTextField resultField){
double area = 0;
int sum = 0;
for (int i = 0; i coord[0].length-1; i++) {
sum = sum + coord[0][i]*coord[1][i+1]-coord[1][i]*coord[0][i+1];
}
sum = sum + coord[0][coord[0].length-1]*coord[1][0]-coord[1][coord[0].length-1]*coord[0][0];
area = 0.5*Math.abs(sum);
resultField.setText(area+"");
}
}
//生成填写坐标的面板的事件
class CreatePanelActionListener implements ActionListener{
private JFrame frame;
public CreatePanelActionListener(JFrame frame){
this.frame = frame;
}
public void actionPerformed(ActionEvent eve) {
String cntStr = ((CalculateArea)frame).getCntField().getText();
JPanel panel = ((CalculateArea)frame).getPanel();
panel.removeAll();
int cnt=0;
//获取填写的多边形坐标数
try{
cnt = Integer.parseInt(cntStr);
}catch (Exception e) {
JLabel label = new JLabel("请输入大于等于3的整数!");
label.setBounds(70, 200, 295, 20);
panel.add(label);
((CalculateArea)frame).repaint();
}
if(cnt=2){
JLabel label = new JLabel("请输入大于等于3的整数!");
label.setBounds(70, 200, 295, 20);
panel.add(label);
((CalculateArea)frame).repaint();
}else{
panel.setLayout(new FlowLayout());
panel.setPreferredSize(new Dimension(260,25*cnt+25));
panel.setSize(new Dimension(260,25*cnt+25));
//清除填写坐标面板上的所有控件
JLabel label = new JLabel("请输入每个点的坐标:");
label.setPreferredSize(new Dimension(260, 20));
panel.add(label);
label = new JLabel("(注:必须按顺时针或逆时针依次填入坐标!)");
label.setForeground(Color.red);
label.setPreferredSize(new Dimension(260, 20));
panel.add(label);
//填写坐标的标签和输入框
JLabel[] coordinateLabels = new JLabel[cnt];
JTextField[][] coordinateFields = new JTextField[2][cnt];
for (int i = 0; i cnt; i++) {
coordinateLabels[i] = new JLabel("第"+(i+1)+"点:");
coordinateLabels[i].setPreferredSize(new Dimension( 45, 20));
panel.add(coordinateLabels[i]);
JLabel labelx = new JLabel("X:");
labelx.setPreferredSize(new Dimension(20, 20));
panel.add(labelx);
coordinateFields[0][i] = new JTextField();
coordinateFields[0][i].setPreferredSize(new Dimension(70, 20));
panel.add(coordinateFields[0][i]);
JLabel labely = new JLabel("Y:");
labely.setPreferredSize(new Dimension(20, 20));
panel.add(labely);
coordinateFields[1][i] = new JTextField();
coordinateFields[1][i].setPreferredSize(new Dimension(70, 20));
panel.add(coordinateFields[1][i]);
}
((CalculateArea)frame).setCoordinateFields(coordinateFields);
((CalculateArea)frame).repaint();
}
}
}
java color 赋值
如果你指的的color是java.awt.Color的对象的话,那么:
构造方法摘要
Color(ColorSpace cspace, float[] components, float alpha)
创建具有 float 数组中指定的颜色分量和指定的 alpha 值的指定 ColorSpace 中的颜色。
Color(float r, float g, float b)
创建具有指定红色、绿色和蓝色值的不透明的 sRGB 颜色,这三个颜色值都在 (0.0 - 1.0) 的范围内。
Color(float r, float g, float b, float a)
创建具有指定红色、绿色、蓝色和 alpha 值的 sRGB 颜色,这些值都在 (0.0 - 1.0) 的范围内。
Color(int rgb)
创建具有指定组合的 RGB 值的不透明的 sRGB 颜色,此 sRGB 值的 16-23 位表示红色分量,8-15 位表示绿色分量,0-7 位表示蓝色分量。
Color(int rgba, boolean hasalpha)
创建具有指定组合的 RGBA 值的 sRGB 颜色,此 RGBA 值的 24-31 位表示 alpha 分量,16-23 位表示红色分量,8-15 位表示绿色分量,0-7 位表示蓝色分量。
Color(int r, int g, int b)
创建具有指定红色、绿色和蓝色值的不透明的 sRGB 颜色,这些值都在 (0 - 255) 的范围内。
Color(int r, int g, int b, int a)
创建具有指定红色、绿色、蓝色和 alpha 值的 sRGB 颜色,这些值都在 (0 - 255) 的范围内。
java中color 类的常见作用作用
Color.RED等常量可以直接用,或者用Color(int r,int g,int b)构造函数,分别代表红绿蓝的参数0-255
很多地方需要设置颜色,都要用这个
java常量
static Color black
static Color BLACK
static Color blue
static Color BLUE
static Color cyan
static Color CYAN
static Color DARK_GRAY
static Color darkGray
static Color gray
static Color GRAY
static Color green
static Color GREEN
static Color LIGHT_GRAY
static Color lightGray
static Color magenta
static Color MAGENTA
static Color orange
static Color ORANGE
static Color pink
static Color PINK
static Color red
static Color RED
static Color white
static Color WHITE
static Color yellow
static Color YELLOW
java中如何从Color属性字符串中获取颜色Color
试试这个
int r=182;
int g=169;
int b=48;
textArea.setForeground(new Color(r,g,b));
color坐标java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于xyz坐标颜色、color坐标java的信息别忘了在本站进行查找喔。