当前位置: 技术问答>java相关
菜鸟求助:在 JAVA APPLET 里如何旋转 90 度显示一个字符?
来源: 互联网 发布时间:2015-03-12
本文导语: | import java.awt.*; import java.awt.event.*; import javax.swing.*; class TextRotatePanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2=(Graphics2D)g; g2.drawString("1.文本未旋转",10,100); g2.rotate(3....
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TextRotatePanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
g2.drawString("1.文本未旋转",10,100);
g2.rotate(3.1415926/2,100,100);
g2.drawString("2.文本顺时针旋转90度^_^",100,100);
g2.drawString("2.1 文本顺时针旋转90度^_^",110,120);
g2.drawString("2.2 文本顺时针旋转90度^_^",120,140);
g2.rotate(-(3.1415926/2),100,100);
g2.drawString("3.文本恢复水平",150,100);
g2.rotate(3.1415926/2,250,100);
g2.drawString("4.文本顺时针旋转90度^_^",250,100);
}
}
class TextRotateFrame extends JFrame
{
public TextRotateFrame()
{
setTitle("文本旋转");
setSize(400,300);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
JTabbedPane tabPane=new JTabbedPane();
tabPane.addTab("1",new JPanel());
//tabPane.add(new TextRotatePanel(),"test"); //也可以
tabPane.addTab("test",new TextRotatePanel());
Container contentPane=getContentPane();
contentPane.add(tabPane);
}
}
public class TextRotate
{
public static void main(String[] args)
{
JFrame objFrame=new TextRotateFrame();
objFrame.show();
}
}
import java.awt.event.*;
import javax.swing.*;
class TextRotatePanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
g2.drawString("1.文本未旋转",10,100);
g2.rotate(3.1415926/2,100,100);
g2.drawString("2.文本顺时针旋转90度^_^",100,100);
g2.drawString("2.1 文本顺时针旋转90度^_^",110,120);
g2.drawString("2.2 文本顺时针旋转90度^_^",120,140);
g2.rotate(-(3.1415926/2),100,100);
g2.drawString("3.文本恢复水平",150,100);
g2.rotate(3.1415926/2,250,100);
g2.drawString("4.文本顺时针旋转90度^_^",250,100);
}
}
class TextRotateFrame extends JFrame
{
public TextRotateFrame()
{
setTitle("文本旋转");
setSize(400,300);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
JTabbedPane tabPane=new JTabbedPane();
tabPane.addTab("1",new JPanel());
//tabPane.add(new TextRotatePanel(),"test"); //也可以
tabPane.addTab("test",new TextRotatePanel());
Container contentPane=getContentPane();
contentPane.add(tabPane);
}
}
public class TextRotate
{
public static void main(String[] args)
{
JFrame objFrame=new TextRotateFrame();
objFrame.show();
}
}