【发布时间】:2014-10-19 18:07:32
【问题描述】:
public class Contact {
int x0,x1,y2=1500,x3=1500,a=0;
JFrame jf;
private JTextField name = new JTextField();
private JTextField phone;
private JButton start;
boolean clicked=false;
static Dimension dim=Toolkit.getDefaultToolkit().getScreenSize();
static int w=(int)dim.getWidth(); static int h=(int)dim.getHeight();
IntroInner d=new IntroInner(); int c;
public Contact() {
}
public void build() throws Exception{
jf=new JFrame("THE COUNTRY CLUB");
jf.getContentPane().add(d);
jf.setSize(w,h);
jf.setVisible(true);
jf.setAlwaysOnTop(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public class IntroInner extends JPanel{
public void paintComponent(Graphics g1){
Graphics2D g=(Graphics2D) g1;
FontMetrics metrics = g.getFontMetrics();
int xpos=(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2-215;
setFont(new Font("serif",Font.ITALIC,40));
g.setColor(Color.black);
g.fillRect(0,0,this.getWidth(),this.getHeight());
Image im1=new ImageIcon("Images/bg.jpg").getImage();
g.drawImage(im1,0,0,this);
//g.rotate(a);
Image im=new ImageIcon("Images/logo.png").getImage();
g.drawImage(im,xpos,50,this);
g.setColor(Color.white);
g.drawString("Please Enter Your Details",400,400);
g.drawString("Name:",400,475);
g.drawString("Contact No:",400,550);
}
}
public static void main(String[] args) throws Exception{
new Contact().build();
}
}
关于在 java 中使用 graphics2d 实现文本字段到 java 框架,我提出了很多建议。但没有得到任何有用的意见。我也在stackoverflow中找到了一些东西。但这也没有帮助我。任何人都可以在这方面帮助我。该程序的预期输出如下所示:提前致谢。
【问题讨论】:
-
您能解释一下为什么在已经有可以为您完成这项工作的全功能组件的情况下要这样做吗?
-
I reffered alot about implementing textfield to java frame using graphics2d in java- 我完全不知道那句话是什么意思。图形用于在 GUI 上绘制一些东西。文本字段用于接受键盘输入。这两个概念有什么关系?
标签: java swing textfield graphics2d