本文整理汇总了Java中java.awt.Graphics.drawRect方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.drawRect方法的具体用法?Java Graphics.drawRect怎么用?Java Graphics.drawRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics
的用法示例。
在下文中一共展示了Graphics.drawRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
if (zoomming) {
g.setColor(Color.BLUE);
if (xStart < xEnd && yStart < yEnd) {
g.drawRect(xStart, yStart, xEnd - xStart, yEnd - yStart);
}
if (xStart < xEnd && yStart > yEnd) {
g.drawRect(xStart, yEnd, xEnd - xStart, yStart - yEnd);
}
if (xStart > xEnd && yStart < yEnd) {
g.drawRect(xEnd, yStart, xStart - xEnd, yEnd - yStart);
}
if (xStart > xEnd && yStart > yEnd) {
g.drawRect(xEnd, yEnd, xStart - xEnd, yStart - yEnd);
}
}
}
示例2: paintBorder
import java.awt.Graphics; //导入方法依赖的package包/类
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
g.translate( x, y );
g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
g.drawRect( 0, 0, w - 1, h - 1 );
g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
g.drawLine( 1, 1, w - 2, 1 );
g.drawLine( 1, 2, 1, 2 );
g.drawLine( 1, h - 2, 1, h - 2 );
g.translate( -x, -y );
}
示例3: paintComponent
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
// TODO: Give "priorities" and always pick color of a notice with
// highest priority (e.g. parsing errors will usually be red).
Color borderColor = getColor();
if (borderColor==null) {
borderColor = Color.DARK_GRAY;
}
Color fillColor = getBrighterColor(borderColor);
int w = getWidth();
int h = getHeight();
g.setColor(fillColor);
g.fillRect(0,0, w,h);
g.setColor(borderColor);
g.drawRect(0,0, w-1,h-1);
}
示例4: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override public void paint(Graphics graphics) {
graphics.setColor(Color.BLACK);
((Graphics2D)graphics).draw(shape);
graphics.setFont(graphics.getFont().deriveFont(10f));
graphics.drawString("ALU", 30, 14);
graphics.drawString("74181", 25, 30);
graphics.setFont(graphics.getFont().deriveFont(8f));
graphics.drawString("M", 10, 56);
graphics.drawString("Cn", 10, 64);
graphics.drawString("P", size.width-14, 20);
graphics.drawString("G", size.width-14, 28);
graphics.drawString("Cn+4", size.width-28, 46);
graphics.drawString("A=B", size.width-24, 64);
for(int number=0;number<=3;number++) {
int top = 75+number*20;
graphics.drawRect(5, top, size.width-10, 20);
graphics.drawString("A"+number, 11, top+8);
graphics.drawString("B"+number, 11, top+18);
graphics.drawString("S"+number, 10, 12+number*10);
graphics.drawString("F"+number, size.width-18, top+13);
}
ContactUtilities.paintSolderingJoints(graphics, contacts);
}
示例5: show
import java.awt.Graphics; //导入方法依赖的package包/类
private void show(String title) {
Frame frame = new Frame() {
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(buffImage, 0, 0, this);
g.setColor(Color.GRAY);
g.drawRect(0, 0, width, height);
g.drawRect(0, height / 2, width, height / 2);
g.drawRect(width / 2, 0, width / 2, height);
}
};
frame.setTitle(title);
frame.setSize(width, height);
frame.setVisible(true);
}
示例6: paintComponent
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (focused) {
Color bdr = UIManager.getColor("Tree.selectionBorderColor"); //NOI18N
if (bdr == null) {
//Button focus color doesn't work on win classic - better to
//get the color from a value we know will work - Tim
if (getForeground().equals(Color.BLACK)) { //typical
bdr = getBackground().darker();
} else {
bdr = getForeground().darker();
}
}
g.setColor(bdr);
g.drawRect(1, 1, getWidth() - 3, getHeight() - 3);
g.setColor(bdr);
}
}
示例7: paintIcon
import java.awt.Graphics; //导入方法依赖的package包/类
public void paintIcon(Component c, Graphics g, int x, int y) {
g.setColor(Color.black);
g.drawRect(x, y, swatchWidth-1, swatchHeight-1);
if (color != null) {
g.setColor(color);
g.fillRect(x+1, y+1, swatchWidth-2, swatchHeight-2);
}
else {
// paint no color and a "nil" if the color is null
g.setColor(UIManager.getColor("controlText"));
g.setFont(FONT);
g.drawString("nil",
x+(swatchWidth - g.getFontMetrics(FONT).stringWidth("nil"))/ 2,
y+(swatchHeight + g.getFontMetrics(FONT).getAscent())/2);
}
}
示例8: drawGroove
import java.awt.Graphics; //导入方法依赖的package包/类
public static void drawGroove(Graphics g, int x, int y, int w, int h,
Color shadow, Color highlight)
{
Color oldColor = g.getColor(); // Make no net change to g
g.translate(x, y);
g.setColor(shadow);
g.drawRect(0, 0, w-2, h-2);
g.setColor(highlight);
g.drawLine(1, h-3, 1, 1);
g.drawLine(1, 1, w-3, 1);
g.drawLine(0, h-1, w-1, h-1);
g.drawLine(w-1, h-1, w-1, 0);
g.translate(-x, -y);
g.setColor(oldColor);
}
示例9: paintIcon
import java.awt.Graphics; //导入方法依赖的package包/类
@Override public void paintIcon(Component c, Graphics g, int x, int y)
{
g.setColor(color);
g.fillRect(x, y, size, size);
g.setColor(Color.DARK_GRAY);
g.drawRect(x, y, size-1, size-1);
}
示例10: drawRocketWithBrakes
import java.awt.Graphics; //导入方法依赖的package包/类
private void drawRocketWithBrakes(Graphics g, int startX,int startY, int rW, int rH, int bDist, int bW, int bH)
{
g.drawOval(startX - rW, startY - rH, 2*rW, 2*rH);
if(window.telemetry_booster_brakes[1]) //left
g.fillRect(startX - rW - bDist - 2*bH, startY - bW, 2*bH, 2*bW);
else g.drawRect(startX - rW - bDist - 2*bH, startY - bW, 2*bH, 2*bW);
if(window.telemetry_booster_brakes[0]) //top
g.fillRect(startX - bW, startY - rH - bDist - 2*bH, 2*bW, 2*bH);
else g.drawRect(startX - bW, startY - rH - bDist - 2*bH, 2*bW, 2*bH);
if(window.telemetry_booster_brakes[3]) //right
g.fillRect(startX + rW + bDist, startY - bW, 2*bH, 2*bW);
else g.drawRect(startX + rW + bDist, startY - bW, 2*bH, 2*bW);
if(window.telemetry_booster_brakes[2]) //bottom
g.fillRect(startX - bW, startY + rH + bDist, 2*bW, 2*bH);
else g.drawRect(startX - bW, startY + rH + bDist, 2*bW, 2*bH);
}
示例11: paint
import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g)
{
g.drawRect(10, 10, 450, 400);
g.drawLine(10, 210, 460, 210);
switch(flag)
{
case 1:
//sin
for(int i = 10; i < 370; i++)
{
x = i;
y = 210 - (int)(100*Math.sin((x-10)*Math.PI/180.0));
g.drawLine(x, y, x, y);
}
break;
case 2:
//cos
for(int i = 10; i < 370; i++)
{
x = i;
y = 210 - (int)(100*Math.cos((x-10)*Math.PI/180.0));
g.drawLine(x, y, x, y);
}
break;
default:
break;
}
}
示例12: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
determinePreferredSize();
super.paint(g);
if (this.filePane.fc.isMultiSelectionEnabled()) {
if (this.pointChanged) {
if (this.mpcx < 0) {
this.tx = this.mpcx + this.mpx;
this.mpcx *= -1;
} else {
this.tx = this.mpx;
}
if (this.mpcy < 0) {
this.ty = this.mpcy + this.mpy;
this.mpcy *= -1;
} else {
this.ty = this.mpy;
}
this.pointChanged = false;
}
this.selectionRect = new Rectangle(this.tx, this.ty, this.mpcx, this.mpcy);
if (this.mouseDownFlag) {
g.setColor(new Color(RapidLookTools.getColors().getFileChooserColors()[0].getRed(), RapidLookTools
.getColors().getFileChooserColors()[0].getGreen(),
RapidLookTools.getColors().getFileChooserColors()[0].getBlue(), 40));
g.fillRect(this.tx, this.ty, this.mpcx, this.mpcy);
g.setColor(RapidLookTools.getColors().getFileChooserColors()[0]);
g.drawRect(this.tx, this.ty, this.mpcx, this.mpcy);
updateSelectionsForDrag();
}
}
}
示例13: paint
import java.awt.Graphics; //导入方法依赖的package包/类
/**
* Draws an indicator that the caret is being selected. Here, we'll draw a red
* rectangle around the value.
*/
@Override
public void paint(InstancePainter painter) {
Bounds bds = painter.getBounds();
BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
int len = (width.getWidth() + 3) / 4;
Graphics g = painter.getGraphics();
g.setColor(Color.RED);
int wid = 7 * len + 2; // width of caret rectangle
int ht = 16; // height of caret rectangle
g.drawRect(bds.getX() + (bds.getWidth() - wid) / 2, bds.getY() + (bds.getHeight() - ht) / 2, wid, ht);
g.setColor(Color.BLACK);
}
示例14: paintComponent
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
double[] x = model.getListObservations();
super.paintComponent(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, 202, 202);
//Draw Border
g.setColor(Color.BLACK);
g.drawRect(0, 0, 202, 202);
//Draw gray lines\
Graphics2D g1 = (Graphics2D) g;
g1.setColor(Color.LIGHT_GRAY);
for (int i = 1; i < 9; i++) {
g1.drawLine(1, 1 + (i * (202 / 9)), 201, 1 + (i * (202 / 9)));
g1.drawLine(1 + (i * (202 / 9)), 1, 1 + (i * (202 / 9)), 202);
}
g1.setColor(Color.BLACK);
for (int i = 1; i < 9; i++) {
g1.drawLine(1, 1 + (i * (202 / 9)), 6, 1 + (i * (202 / 9)));
g1.drawLine(1 + (i * (202 / 9)), 1, 1 + (i * (202 / 9)), 6);
g1.drawLine(197, 1 + (i * (202 / 9)), 202, 1 + (i * (202 / 9)));
g1.drawLine(1 + (i * (202 / 9)), 198, 1 + (i * (202 / 9)), 202);
}
//Draw graph
//Draw reference line
g.setColor(Color.BLUE);
for (int i = 0; i < x.length; i++) {
g.fillOval((int) Math.round((x[i] / x[x.length-1]) * 200),
200 - (int) Math.round((i*(1d/x.length)) * 200), 5, 5);
}
//g.fillOval(200,1, 5, 5);
}
示例15: paintIcon
import java.awt.Graphics; //导入方法依赖的package包/类
public void paintIcon(Component c, Graphics g, int x, int y) {
Color col = g.getColor();
try {
g.setColor(Color.GREEN);
g.drawRect(x, y, getIconWidth(), getIconHeight());
g.fillRect(x+3, y+3, getIconWidth()-5, getIconHeight()-5);
} finally {
g.setColor(col);
}
}