import java.awt.Graphics;
創(chuàng)新互聯(lián)公司制作網(wǎng)站網(wǎng)頁找三站合一網(wǎng)站制作公司,專注于網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,網(wǎng)站設(shè)計(jì),企業(yè)網(wǎng)站搭建,網(wǎng)站開發(fā),建網(wǎng)站業(yè)務(wù),680元做網(wǎng)站,已為數(shù)千家服務(wù),創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)將一如既往的為我們的客戶提供最優(yōu)質(zhì)的網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷推廣服務(wù)!
import java.awt.Point;
import java.util.Scanner;import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;public class arrow extends JPanel{
static Point [] point=new Point[8];
static int w,h,d;
public arrow() {
}
public static void main(String[] args) {
InitialPoint();
showView();
}
static void showView()
{
JFrame frame=new JFrame("繪制箭頭");
frame.getContentPane().add(new arrow());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
}
static void InitialPoint()
{
Scanner input=new Scanner(System.in);
System.out.println("請(qǐng)你書箭頭的寬w值0--500:");
w=input.nextInt();
System.out.println("請(qǐng)你書箭頭的高h(yuǎn)值0--250:");
h=input.nextInt();
System.out.println("請(qǐng)你書箭頭的長(zhǎng)度d值0--500:");
d=input.nextInt();
for(int i=0;i8;i++)
point[i]=new Point();
if(w=0w=500h=0h=250d=0d=500d2*h)
{
point[0].x=-d/2;point[0].y=0;
point[2].x=-d/2+h;point[2].y=-w/2;
point[1].x=-d/2+h;point[1].y=w/2;
point[3].x=-d/2;point[3].y=0;
point[4].x=d/2;point[4].y=0;
point[5].x=d/2-h;point[5].y=w/2;
point[6].x=d/2-h;point[6].y=-w/2;
point[7].x=d/2;point[7].y=0;
}
else {
System.out.println( "數(shù)據(jù)不符合條件");
}
for(int i=0;i8;i++)
{
point[i].x=point[i].x+250;
point[i].y=point[i].y+250;
}
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
for(int i=0;i7;i++)
{
g.drawLine(point[i].x,point[i].y , point[i+1].x,point[i+1].y);
}
}
}
用java實(shí)現(xiàn)的,你看看。。。
小箭頭可以是一個(gè)圖片 默認(rèn)是隱藏的 等你隱藏了窗體就把小箭頭顯示,點(diǎn)擊小箭頭再顯示窗體隱藏小箭頭,就這樣切來切去嘛
break表示跳出循環(huán)了,后面的println永遠(yuǎn)不會(huì)運(yùn)行所以是無效代碼,java對(duì)這些無效代碼的編譯就是報(bào)錯(cuò)
/**
* 畫帶箭頭的線
* */
public void paintk(GC g, int x1, int y1, int x2, int y2) {
double H = 10 ; // 箭頭高度
double L = 7 ; // 底邊的一半
int x3 = 0 ;
int y3 = 0 ;
int x4 = 0 ;
int y4 = 0 ;
double awrad = Math.atan(L / H); // 箭頭角度
double arraow_len = Math.sqrt(L * L + H * H); // 箭頭的長(zhǎng)度
double [] arrXY_1 = rotateVec(x2 - x1, y2 - y1, awrad, true , arraow_len);
double [] arrXY_2 = rotateVec(x2 - x1, y2 - y1, - awrad, true , arraow_len);
double x_3 = x2 - arrXY_1[ 0 ]; // (x3,y3)是第一端點(diǎn)
double y_3 = y2 - arrXY_1[ 1 ];
double x_4 = x2 - arrXY_2[ 0 ]; // (x4,y4)是第二端點(diǎn)
double y_4 = y2 - arrXY_2[ 1 ];
Double X3 = new Double(x_3);
x3 = X3.intValue();
Double Y3 = new Double(y_3);
y3 = Y3.intValue();
Double X4 = new Double(x_4);
x4 = X4.intValue();
Double Y4 = new Double(y_4);
y4 = Y4.intValue();
// g.setColor(SWT.COLOR_WHITE);
// 畫線
g.drawLine(x1, y1, x2, y2);
// 畫箭頭的一半
g.drawLine(x2, y2, x3, y3);
// 畫箭頭的另一半
g.drawLine(x2, y2, x4, y4);
}
/**
*取得箭頭的繪畫范圍
*/
public double [] rotateVec( int px, int py, double ang, boolean isChLen,
double newLen) {
double mathstr[] = new double [ 2 ];
// 矢量旋轉(zhuǎn)函數(shù),參數(shù)含義分別是x分量、y分量、旋轉(zhuǎn)角、是否改變長(zhǎng)度、新長(zhǎng)度
double vx = px * Math.cos(ang) - py * Math.sin(ang);
double vy = px * Math.sin(ang) + py * Math.cos(ang);
if (isChLen) {
double d = Math.sqrt(vx * vx + vy * vy);
vx = vx / d * newLen;
vy = vy / d * newLen;
mathstr[ 0 ] = vx;
mathstr[ 1 ] = vy;
}
return mathstr;
}
網(wǎng)站題目:java箭頭代碼,java箭頭符號(hào)
文章鏈接:http://aaarwkj.com/article16/dsiisdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、用戶體驗(yàn)、微信公眾號(hào)、、外貿(mào)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)