展开全部
import java.awt.*;
import javax.swing.*;
public class ShowRoundChar extends JPanel{
Font font = new Font("宋体",Font.PLAIN,40);
String display = "这是一个e5a48de588b662616964757a686964616f31333264646463测试语句,没其他意思!";
char [] cdis = display.toCharArray();
Point [] cpos = null;
Point[] createPos(FontMetrics fm,char[] cdis, Point center,int radio){
if(cdis == null||cdis.length == 0)
return null;
Point [] cpos = new Point[cdis.length];
double d_angle = 2*Math.PI/cpos.length;
double angle = 0;
int index = 0;
while(index
double cx = center.x+radio*Math.cos(angle) - fm.charWidth(cdis[index])/2;
double cy = center.y+radio*Math.sin(angle) + fm.getAscent()/2;
cpos[index] = new Point((int)cx,(int)cy);
angle += d_angle;
index++;
}
return cpos;
}
void drawString(Graphics g){
g.setColor(Color.BLUE);
int index = 0;
while(index
g.drawString(cdis[index]+"", cpos[index].x, cpos[index].y);
index++;
}
}
public void paint(Graphics g){
g.setFont(font);
Point center = new Point(200,200);
cpos = createPos(g.getFontMetrics(),cdis,center,150);
drawOval(g,center,150);
drawString(g);
}
public void drawOval(Graphics g,Point center,int radio){
//g.setColor(Color.RED);
g.setColor(new Color(125<<24|255<<16|0<<8|0));
g.drawOval(center.x-radio, center.y-radio, radio*2, radio*2);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,430);
frame.add(new ShowRoundChar());
frame.setVisible(true);
}
}