norm i think im screwing up here :/..
i wanna start from the beginning.
So to begin with, i will need a text area where the user will type in. But for now we can use a String variable.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
norm i think im screwing up here :/..
i wanna start from the beginning.
So to begin with, i will need a text area where the user will type in. But for now we can use a String variable.
What is the question?
If you don't understand my answer, don't ignore it, ask a question.
Ajan (April 12th, 2012)
from my last post. how would i start the print method?
keeping in my mind:
Must print multiple lines
Must print multiple pages
Must print within its borders.
So can you guide me through this problem please?
Create a special test program to work out the logic. Create a class that extends JPanel, override its paintComponent() method and add an instance of it to a JFrame so you can see the results.
In the paintComponent method, add code that is almost exactly the same as the code in your drawString() method. Have the code take a String with \n characters, split it and draw the substrings that are in the array returned by split using the Graphics drawstring() method in a loop where the value of the y location is increased each time around the loop.
If you don't understand my answer, don't ignore it, ask a question.
could you go step by step with me?
ok so, made the GUI:
import javax.swing.JFrame; import javax.swing.JPanel; /** * * @author User */ public class Frame extends javax.swing.JFrame { String textPrint; /** Creates new form Frame */ public Frame() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); text = new javax.swing.JTextArea(); Print = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); text.setColumns(20); text.setRows(5); jScrollPane1.setViewportView(text); Print.setText("Print"); Print.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PrintActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 618, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(267, 267, 267) .addComponent(Print) .addContainerGap(296, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(54, 54, 54) .addComponent(Print) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void PrintActionPerformed(java.awt.event.ActionEvent evt) { textPrint = text.getText(); JFrame frame = new JFrame(); JPanel drawArea = new JPanel(); frame.add(drawArea); frame.setSize(500, 600); frame.setVisible(true); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url] */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Frame().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton Print; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea text; // End of variables declaration }
So where to from here?
I havent used the paintComponent before.
What is all that code for?
Reread my suggestion in post#29. There are two classes: JFrame with a main() method and JPanel with a paintComponent() method. No more.
If you don't understand my answer, don't ignore it, ask a question.