|
You should have a database layer. It should NOT have any gui code in it.
It provides a public API that allows an external caller to interact with the layer.
The layer interacts with the database.
That public API would have a method/class that would represent "save interval" and "get interval" where the 'interval' values represent '1 month', '3 Months', '6 months' (and note that I am NOT saying to store "1 month" as a value.)
The 'save' method uses a database insert or perhaps update statement. And the 'get' uses a database query statement.
You code that and test it.
After you do that THEN your gui code, specifically the JSpinner uses the two methods.
|
|
|
|
|
Can anyone guide me how to write code to generate public and private keys using RSA algorithm, using your own functions? In other words, not using BigInteger etc. This seems impossible and I have a deadline of 31 October, 2013.
|
|
|
|
|
|
I'm not able to move forward with the ResultSet with this code on "next Button".
Here is the code
public void nextrecord()
{
Statement stmt = null;
String query = "select * from Employer";
try {
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(query);
if(rs.isBeforeFirst());
{
while(rs.next())
{
firstNameTextField.setText(rs.getString(2));
lastNameTextField.setText(rs.getString(3));
addressTextField.setText(rs.getString(4));
}
}
}
catch (SQLException e )
{
e.printStackTrace();
}
}
The problem is when I click on the next button ,it takes me to the last record and skips all the records ,I wanted to go through all the records one by one ,clicking each record one by one.
There is one record present in the text fields before pressing next button.
|
|
|
|
|
Separate your actions...
0. Method to query the data, then store the record set.
1. Method to display a record.
Something like [untested code]
class Hatstand
extends Stuff
{
private RecordSet recordSet;
private void submitQuery()
{
Statement stmt = null;
String query = "select * from Employer";
try
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
this.recordSet = stmt.executeQuery(query);
}
catch (SQLException e )
{
e.printStackTrace();
this.recordSet = null;
}
finally
{
setRecord(true);
}
}
private void setRecord(boolean forward)
{
boolean isNull = true;
if (this.RecordSet != null)
{
if (forward && !this.RecordSet.isLast())
{
this.RecordSet.next();
isNull = false;
}
else if (!forward && !this.RecordSet.isFirst())
{
this.RecordSet.previous();
isNull = false;
}
}
if (isNull)
{
firstNameTextField.setText(null);
lastNameTextField.setText(null);
addressTextField.setText(null); }
}
else
{
firstNameTextField.setText(rs.getString(2));
lastNameTextField.setText(rs.getString(3));
addressTextField.setText(rs.getString(4)); }
}
}
}
speramus in juniperus
|
|
|
|
|
Thanks for the Idea.
|
|
|
|
|
I have a String which has been splitted like this
String companyinforstring ="Company name.:Company profile no 1.:Company profile no 2.:Company profile no3.:---------------------------------------------------------------:Company address, :Street number, :Area,Area no2, :City. ";
for (String retval: companyinforstring.split(":"))
{
System.out.println(retval);
graphics.drawString(retval.toUpperCase(), 250, 200);
}
The Problem is that String which has been splitted, overlaping each String,How can this be solved?
|
|
|
|
|
graphics.drawString(retval.toUpperCase(), 250, 200);
You are drawing every line at the same point.
Veni, vidi, abiit domum
|
|
|
|
|
String[] str1 = companyinforstring.split(":");
for(int i=0;i<str1.length;i++)
{
graphics.drawString(str1[0].toUpperCase(), 360, 50);
graphics.drawString(str1[1].toUpperCase(), 360, 60);
graphics.drawString(str1[2].toUpperCase(), 360, 70);
graphics.drawString(str1[3].toUpperCase(), 360, 80);
graphics.drawString(str1[4].toUpperCase(), 360, 90);
graphics.drawString(str1[5].toUpperCase(), 360, 100);
graphics.drawString(str1[6].toUpperCase(), 360, 110);
graphics.drawString(str1[7].toUpperCase(), 360, 120);
graphics.drawString(str1[8].toUpperCase(), 360, 130);
}
Is there any simple way of doing it?
Please let me know
|
|
|
|
|
chdboy wrote: Is there any simple way of doing it? Of course, use a loop, something like:
int lineHeight = 10;
int currentLine = 50;
for (String strText: companyinforstring.split(":"))
{
graphics.drawString(strText.toUpperCase(), 360, currentLine);
currentLine += lineHeight;
}
Veni, vidi, abiit domum
|
|
|
|
|
thanks a lot
|
|
|
|
|
Using applets i create one text editor in there when they enter maximum words cursor should go to the new page this is my issue . so if any know know how to overcome this problem pls help me out.
Thanks and Regards.
Naveenkrishna
|
|
|
|
|
Member 10356313 wrote: pls help me out. With what? All you have given us is a description of what you think your code should do.
Veni, vidi, abiit domum
|
|
|
|
|
This code i wrote to create the editor. Everything is working fine but if I entered maximum characters cursor is not moving to new page.
public JTextComponent createEditor(final Source source)
{
if(source.getSourceType() == Source.SERIALIZATION)
return deserializeEditor(source.getSerializedObject());
if(source.getSourceType() == Source.CONTENT)
return createEditorFromPage(new Page() {
public void setPage(JTextPane pane)
{
if(source.getBaseUrl() != null)
try
{
URL baseUrl = new URL(source.getBaseUrl());
((HTMLDocument)pane.getDocument()).setBase(baseUrl);
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
pane.setText(source.getContent());
}
});
else
return createEditorFromPage(new Page() {
public void setPage(JTextPane pane)
throws IOException
{
pane.setPage(source.getSourceUrl());
}
});
}
public JTextComponent createEditorFromPage(Page page)
{
JTextPane p = new JTextPane();
Dimension dim = new Dimension(labelDimension.getWidth(), labelDimension.getHeight());
p.setPreferredSize(dim);
p.setMaximumSize(dim);
p.setSize(dim);
HTMLEditorKit kit = createEditorKit();
p.setEditorKit(kit);
p.setTransferHandler(new PlainTextTransferHandler());
if(page != null)
try
{
page.setPage(p);
}
catch(IOException e)
{
System.err.println("Attempted to read a bad URL: " + e.getMessage());
}
else
System.out.println("create empty label");
javax.swing.text.Style style = p.addStyle("24pts", null);
StyleConstants.setFontSize(style, 24);
style = p.addStyle("12pts", null);
StyleConstants.setFontSize(style, 12);
style = p.addStyle("Italics", null);
StyleConstants.setItalic(style, true);
style = p.addStyle("Bold", null);
StyleConstants.setBold(style, true);
p.addMouseListener(new PopupMenuMouseListener(new PopupMenuFactory((HTMLDocument)p.getDocument()), p));
p.setDragEnabled(!hiddenMode);
initializeDocument((HTMLDocument)p.getDocument(), p, kit);
return p;
}
|
|
|
|
|
Please use <pre> tags around your code so it looks readable:
if(source.getSourceType() == Source.SERIALIZATION)
return deserializeEditor(source.getSerializedObject());
if(source.getSourceType() == Source.CONTENT)
As to your actual problem you have not explained where in the code you expect it to go to a new page, and what actually happens at that point.
Veni, vidi, abiit domum
|
|
|
|
|
<pre>
if(source.getSourceType() == Source.SERIALIZATION)
return deserializeEditor(source.getSerializedObject());
public JTextComponent deserializeEditor(InputStream inputStream)
{
JTextPane p;
System.out.println("deserialize existing document...");
p = new JTextPane();
p.setPreferredSize(new Dimension(labelDimension.getWidth(), labelDimension.getHeight()));
javax.swing.text.EditorKit kit = createEditorKit();
p.setEditorKit(kit);
ObjectInputStream ois = null;
try
{
ois = new ObjectInputStream(inputStream);
Object obj = null;
if((obj = ois.readObject()) != null && (obj instanceof Document))
{
Document doc = (Document)obj;
p.setDocument(doc);
System.out.println("set deserialized document");
}
}
catch(IOException e)
{
System.err.println(e.getMessage());
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
finally
{
safeClose(ois);
}
p.setDragEnabled(!hiddenMode);
return p;
}
public JTextComponent createEditorFromPage(Page page)
{
JTextPane p = new JTextPane();
Dimension dim = new Dimension(labelDimension.getWidth(), labelDimension.getHeight());
p.setPreferredSize(dim);
p.setMaximumSize(dim);
p.setSize(dim);
HTMLEditorKit kit = createEditorKit();
p.setEditorKit(kit);
p.setTransferHandler(new PlainTextTransferHandler());
if(page != null)
try
{
page.setPage(p);
}
catch(IOException e)
{
System.err.println("Attempted to read a bad URL: " + e.getMessage());
}
else
System.out.println("create empty label");
javax.swing.text.Style style = p.addStyle("24pts", null);
StyleConstants.setFontSize(style, 24);
style = p.addStyle("12pts", null);
StyleConstants.setFontSize(style, 12);
style = p.addStyle("Italics", null);
StyleConstants.setItalic(style, true);
style = p.addStyle("Bold", null);
StyleConstants.setBold(style, true);
p.addMouseListener(new PopupMenuMouseListener(new PopupMenuFactory((HTMLDocument)p.getDocument()), p));
p.setDragEnabled(!hiddenMode);
initializeDocument((HTMLDocument)p.getDocument(), p, kit);
return p;
}
</pre>
Save event is there if they click save event whole HTML image is going to save in BLOB object. In there I'm checking if its already save value or new value if its saved value it call deserializeEditor () in this method binary value is converting to string then it will show in editor if its new string value means just it will call createEditorFromPage() event which i showed in above code.
My problem is when they entering text in editor if its reach maximum characters or maximum lines it should open new page.
Its like "Wold document"
sorry while keypress the value I don't no which event is going to fire.please suggest which event is going to fire with any example.
naveenkrishna
|
|
|
|
|
I'm not able to get the printout.
Here is the code.
public class Billing extends Frame implements ActionListener,Printable
{
JButton printbtn = new JButton("Print");
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (pageIndex > 0)
{
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)graphics;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
graphics.drawString("Hello world!", 100, 100);
return PAGE_EXISTS;
}
public Billing
(
printbtn.addActionListener(this);
JPanel panel = new JPanel();
panel.setLayout(new MigLayout("debug,fillx,filly", "[]rel:push[]", "[]1[]"));
panel.add(printbtn);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
)
@Override
public void actionPerformed(ActionEvent e)
{
else if (e.getSource().equals(printbtn))
{
System.out.println("You have clicked on Print Button!");
PrinterJob pj = PrinterJob.getPrinterJob();
job.setPrintable(this);
if (pj.printDialog() == true)
{
try
{
pj.print();
}
catch (PrinterException exc)
{
System.out.println(exc);
}
}
System.out.println("Print Job Ends Here!!!!XXXXX!!!!");
}
}
|
|
|
|
|
Please get your code to a compilable form - everyone trying to read this has to guess what you actually mean several times to get that right.
Regards,
ab
|
|
|
|
|
Sorry my bad with Copy/Paste
Here is the code once again.
public class Billing extends Frame implements ActionListener,Printable
{
JButton printbtn = new JButton("Print");
JFrame frame = new JFrame();
PrinterJob job = PrinterJob.getPrinterJob();
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (pageIndex > 0)
{
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)graphics;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
graphics.drawString("Hello world!", 100, 100);
return PAGE_EXISTS;
}
public Billing()
{
JPanel panel = new JPanel();
panel.setLayout(new MigLayout("debug,fillx,filly", "[]rel:push[]", "[]1[]"));
panel.add(printbtn);
frame.add(panel);
printbtn.addActionListener(this);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x=(int)((dimension.getWidth() - 760)/2);
int y=(int)((dimension.getHeight() - 550)/2);
frame.setLocation(x, y);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
public static void main(String[] args)
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
e.printStackTrace();
}
new Billing();
}
@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource().equals(printbtn))
{
System.out.println("You have clicked on Print Button!");
PrinterJob pj = PrinterJob.getPrinterJob();
job.setPrintable(this);
if (pj.printDialog() == true)
{
try
{
pj.print();
}
catch (PrinterException exc)
{
exc.printStackTrace();
}
}
System.out.println("Print Job Ends Here!!!!XXXXX!!!!");
}
}
}
}
|
|
|
|
|
So two copies of your code but with no detail about your problem. Please explain exactly what you are trying to do, what results you expect, and what results you see, including the full text of any error messages.
Veni, vidi, abiit domum
|
|
|
|
|
I'm able to print Hello world with the help of my printer machine.
But with that code I don't get any error messages,but I'm able to print those two lines in the Console
1.You have clicked on Print Button!
2.Print Job Ends Here!!!!XXXXX!!!!
But not Hello world from this code
graphics.drawString("Hello world!", 100, 100);
What is wrong with this code?
|
|
|
|
|
|
I have got the solution
I have created two Printer Job
1.
PrinterJob job = PrinterJob.getPrinterJob();
2.
PrinterJob pj = PrinterJob.getPrinterJob();
And If I did this in my code
job.setPrintable(this);
I should not be doing this
if (pj.printDialog() == true)
pj.print();
Instead of "pj" I have to use "job".
that was the problem
I was not using the right job hehe.
|
|
|
|
|
how can i replace the two digits inside the number?
O/P:
536247982
After replacing
537246982
|
|
|
|
|
Write out, on paper, the two numbers and then the steps required to achieve the result. Then convert those steps in native language to Java code. It is really not that difficult. If you need some ideas then look at the Java Tutorial[^], particularly the section on numbers and strings.
Veni, vidi, abiit domum
|
|
|
|
|