Bookmark Topic Watch Topic
  • New Topic

I need to display the system date in a Textfield

 
Prudent Kay
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello everyone and anyone,
I need to display the system date in the textfield, but it is not recognised when i try to do so, the date type is not compatible with the setText() method.
the code is below, I have commented where the error is.
import java.awt.*;
import java.applet.*;
import java.util.Date;
/*<applet code="display" width=200 height=300></applet>*/
public class display extends Applet
{
Label lbl1, lbl2, lbl3;
TextField t1, t2;
Choice clist;
GridBagLayout gb;
GridBagConstraints gbc;
public void init()
{
gb = new GridBagLayout();
setLayout(gb);
gbc = new GridBagConstraints();
lbl1 = new Label("Name:");
lbl2 = new Label("Course Enrolled:");
lbl3 = new Label("Date Enrolled:");
t1 = new TextField(15);
t2 = new TextField(,15);

//display the date in a textfield.
//t2.setText(new Date());
clist = new Choice();

clist.addItem("Office Assistant");
clist.addItem("CPISM");
clist.addItem("DISM");
clist.addItem("HDSE");
clist.addItem("ADSE");
gbc.fill=GridBagConstraints.BOTH;
addComp(lbl1,0,0,1,1);
gbc.fill=GridBagConstraints.BOTH;
addComp(t1,0,1,1,1);
gbc.fill=GridBagConstraints.BOTH;
addComp(lbl2,1,0,1,1);
gbc.fill=GridBagConstraints.BOTH;
addComp(clist,1,1,1,1);
gbc.fill=GridBagConstraints.BOTH;
addComp(lbl3,2,0,1,1);
gbc.fill=GridBagConstraints.BOTH;
addComp(t2,2,1,1,1);


}
public void addComp(Component c, int row, int col, int nrow, int ncol)
{
gbc.gridx=col;
gbc.gridy=row;
gbc.gridwidth=ncol;
gbc.gridheight=nrow;
gb.setConstraints(c, gbc);
add(c);
}

}
Prue.
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Report post to moderator
You've posted this twice so I'll close this thread of the two.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!