Prudent Kay

Greenhorn
+ Follow
since Nov 21, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Prudent Kay

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.
21 years ago
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.
21 years ago
Dear all,
i have created a text editor with menus as those given in a notepad application. i have created the following codes on how to save a file.
FileDialog fd2 = new FileDialog (this, "Save file", FileDialog.SAVE);
FileWriter fw;
if(ae.getActionCommand().equals("Save"))
{
fd2.setVisible(true);
String st,sn;
try
{
sn= nt.fd2.getDirectory()+"/"+nt.fd2.getFile()+".txt";
fw = new FileWriter(sn);
char ch;
String stt=nt.t.getText();
for(int i=0;i<stt.length();i++)
{
ch=stt.charAt(i);
fw.write(ch);

}
fw.close();
}
catch(FileNotFoundException ee){}
catch(IOException eee){}

}
but everytime i click on the save menu the save as dialog box appears even though the file has been saved already, can anyone help me out with the code so that if the file has been saved already the 'save as' dialog box should not reappear but just save the latest changes made.
Thanx.
21 years ago
I have created the following program that accepts values and adds them up when you click on the 'add' button. Can you pliz specify the condition to be used such that the user is not allowed to enter an alphabet or other character. if that happens an error message should be displayed on label l4.
import java.awt.*;
import java.awt.event.*;
class Myframe extends Frame implements ActionListener
{
TextField t1,t2,t3;
Button b1,b2;
Label l1,l2,l3,l4;
Myframe()
{
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
b1=new Button("Add");
b2=new Button("Exit");
l1=new Label("Enter num1");
l2=new Label("Enter num2");
l3=new Label("Result");
l4 = new Label(" ");
setLayout(new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(b2);
add(l4);
b1.addActionListener(this);
b2.addActionListener(this);
setSize(300,300);
setVisible(true);
}
public static void main(String s[])
{
new Myframe();
}
public void actionPerformed(ActionEvent ae)
{
String str1 = t1.getText();
String str2 = t2.getText();
if(ae.getSource()==b1)
{
if(str1 <='a' || str1 >= 'z')
{
la.setText("Enter a number");
}

else
{
int x=Integer.parseInt(str1);
int y=Integer.parseInt(str2);
t3.setText(String.valueOf(x+y));
}

}
else if(ae.getSource()==b2);
{
System.exit(0);
}
}
}
21 years ago
JSP
I have created the following program that accepts values and adds them up when you click on the 'add' button. Can you pliz specify the condition to be used such that the user is not allowed to enter an alphabet or other character. if that happens an error message should be displayed on label l4.
import java.awt.*;
import java.awt.event.*;
class Myframe extends Frame implements ActionListener
{
TextField t1,t2,t3;
Button b1,b2;
Label l1,l2,l3,l4;
Myframe()
{
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
b1=new Button("Add");
b2=new Button("Exit");
l1=new Label("Enter num1");
l2=new Label("Enter num2");
l3=new Label("Result");
l4 = new Label(" ");
setLayout(new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(b2);
add(l4);
b1.addActionListener(this);
b2.addActionListener(this);
setSize(300,300);
setVisible(true);
}
public static void main(String s[])
{
new Myframe();
}
public void actionPerformed(ActionEvent ae)
{
String str1 = t1.getText();
String str2 = t2.getText();
if(ae.getSource()==b1)
{
if(str1 <='a' || str1 >= 'z')
{
la.setText("Enter a number");
}

else
{
int x=Integer.parseInt(str1);
int y=Integer.parseInt(str2);
t3.setText(String.valueOf(x+y));
}

}
else if(ae.getSource()==b2);
{
System.exit(0);
}
}
}
21 years ago