文本输入框怎么编啊??才学的!!
刚学完VB,用JAVA编页面好难,急求各位高手,给下指导!!谢谢!!
------解决方案--------------------package ch09;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.util.*;
public class TextTest
{
public static void main(String[] args)
{
TextTestFrame frame = new TextTestFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class TextTestFrame extends JFrame
{
public TextTestFrame()
{
this.setSize(450, 500);
this.setTitle( "TextTest " + "Test ");
panel = new TextTestPanel();
add(panel,BorderLayout.CENTER);
DocumentListener listener=new TimeChangListener();
JPanel p=new JPanel();
hourField=new JTextField( "12 ",3);
hourField.getDocument().addDocumentListener(listener);
p.add(new JLabel( "Hour: "));
p.add(hourField);
minField=new JTextField( "00 ",3);
minField.getDocument().addDocumentListener(listener);
p.add(new JLabel( "Minute: "));
p.add(minField);
this.add(p,BorderLayout.SOUTH);
pack();
}
public void setClock()
{
try
{
int hours=Integer.parseInt(hourField.getText().trim());
int mintues=Integer.parseInt(minField.getText().trim());
panel.setTime(hours, mintues);
} catch (
NumberFormatException e)
{
}
}
private class TimeChangListener implements DocumentListener
{
public void changedUpdate(DocumentEvent e)
{
setClock();
}
public void insertUpdate(DocumentEvent e)
{
setClock();
}
public void removeUpdate(DocumentEvent e)
{
}
}
JTextField hourField,minField;
TextTestPanel panel;
}
class TextTestPanel extends JPanel
{
public TextTestPanel()
{
setPreferredSize(new Dimension(2*Size+1,2*Size+1));
}
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
Ellipse2D ell=new Ellipse2D.Double(0,0,2*Size,2*Size);
g2.draw(ell);
double hourAngle=Math.toRadians(90-360*mins/(12*60));
double minAngle=Math.toRadians(90-360*mins/60);
drawHand(g2, hourAngle, HourHand);
drawHand(g2,minAngle,MinHand);
}
public void drawHand(Graphics2D g,double angle,double hand)
{
Point2D end=new Point2D.Double(Size+hand*Math.cos(angle),Size-hand*Math.sin(angle));
Point2D center=new Point2D.Double(Size,Size);
g.draw(new Line2D.Double(center,end));
}
public void setTime(int h,int m)
{
mins=h*60+m;
repaint();
System.out.println( "aaa ");
}
private static final int Size=100;
private static final double HourHand=Size*0.6;
private static final double MinHand=Size*0.8;
private int mins=0;
}
我也在学给你个例子
------解决方案--------------------楼上的用SWING???
swing太麻烦了,要创建很多东西,但是很长经验
用JSP编页面不是很简单么
如果用struts标签 <html:text property= " ">
不用标签就是html的输入框 <input type= "text " name= " ">
------解决方案--------------------