Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
C

chdboy

@chdboy
About
Posts
62
Topics
25
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to get Content Pane for a JPanel ?
    C chdboy

    Right now with this code showing label inside the text box I want to use the content pane for giving space in between then .

    void InboundCheque()
    {
    printbtn.setVisible(false);
    //GridLayout glLayout = new GridLayout(3,2,2,10);
    //GroupLayout groupL = new GroupLayout(Inbound);
    // Container contentPane = frame.getContentPane();

    	  SpringLayout groupL = new SpringLayout();
    	  Inbound.setLayout(groupL);
    	  Inbound.add(chqlbl);
    	  Inbound.add(chqstartingdate);
    	  
    	 
      }
    
    Java docker tutorial question

  • JFrame showing nothing.
    C chdboy

    what other details you need?

    Java java graphics

  • JFrame showing nothing.
    C chdboy

    I'm calling this class from another class so it is using that main class main method.

    Java java graphics

  • JFrame showing nothing.
    C chdboy

    I'm not able to see content on JFrame ,when JFrame shows up.

    import java.awt.*;

    import javax.swing.*;
    import java.awt.event.*;
    public class GraphicUse extends JPanel
    {
    public void PaintComponent(Graphics gr)
    {
    super.paintComponents(gr);
    this.setBackground(Color.BLUE);
    gr.setColor(Color.WHITE);
    gr.fillRect(50, 50, 100, 100);
    gr.setColor(new Color(139,38,190));
    gr.fillRect(50, 70, 100, 100);
    gr.setColor(Color.RED);
    gr.drawString("This is a new String", 50, 90);
    }

    public static void main(String\[\] args) 
    {
    }
    

    }

    And displaying it in another class which extends Frame

    JFrame newframe = new JFrame("Color Frame");
    newframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GraphicUse gu = new GraphicUse();
    newframe.add(gu);
    newframe.setSize(250,300);
    newframe.setVisible(true);

    Java java graphics

  • JComboBox and ActionListener.
    C chdboy

    What I want to do is,when ever I click on any Item selected in the Combo Box it should display the result accordingly. My code does that ,but I wanted to know is there any way that I don't use lots of IF statements?Right now it is according to Index of combo box items.

    else if(e.getSource().equals(jcb1))
    {
    int selectedindex = jcb1.getSelectedIndex();
    String comb_string = (String)jcb1.getSelectedItem();
    if(selectedindex==1)
    {
    try {

    			//String sql\_command ="select \* , count(\*) over (partition by 1) total\_rows from Employer where Employername = ? ";				
    			String sql\_command ="select \* from Employer where Employername = ? ";
    				PreparedStatement st=con.prepareStatement(sql\_command);					
    				st.setString(1,comb\_string);
    				Result = st.executeQuery();
    				int test =0;
    				String Store="";
    				String Response ="";
    				test++;
    				if(Result.next())
    				{						
    					String add1=Result.getString(3);
    					first.setText(add1);
    					String add2=Result.getString(28);
    					second.setText(add2);
    					String add3=Result.getString(4);
    					third.setText(add3);
    					String add4=Result.getString(6);
    					fourth.setText(add4);
    					
    					if(test !=0)
    					{
    						/\*Result.absolute(test);
    						DisplayData();\*/
    						Response = "Number of Records that Matches :"+test+Store;
    						JOptionPane.showMessageDialog(null, Response);				
    					}
    					else
    					{
    						JOptionPane.showMessageDialog(null,"Could not be found");
    					}
    					
    					
    				}
    			} catch (SQLException e1) {
    				// TODO Auto-generated catch block
    				e1.printStackTrace();
    			}					
    		}			
    	}	
    

    EDIT: I think

    if(jcb1.getSelectedItem().equals(comb_string))

    this is the solution. I have a JTextField instead ,but what this code does is ,it adds the name which I search into JComboBox and remembers it till the JFrame is open.

    Java database question

  • How to make Integer number increment by 1 in a JTextField?
    C chdboy

    Yes that didn't come to my mind...thank you :)

    Java tutorial question

  • How to make Integer number increment by 1 in a JTextField?
    C chdboy

    ok right now I have not made is permanent,but I think I will save it in the database so when the application loads it will still remember the last file no ...thanks for the Idea. Right now I have done it with this code.

    int fileno1=Integer.parseInt(Result.getString(2));
    int increment = ++fileno1;
    int increment2 = ++increment;
    filenotxtfield.setText(Integer.toString(increment2));

    I have used this code after inserting the data in the database.So now as you suggested I'm working on how to show the next file no upon application starts.

    Java tutorial question

  • How to make Integer number increment by 1 in a JTextField?
    C chdboy

    Do I have to save it in the database and then retrieve it?

    int increment = ++fileno1;

    I have to save increment in the database?

    Java tutorial question

  • How to make Integer number increment by 1 in a JTextField?
    C chdboy

    I'm able to display the value after data is saved, but it is showing me wrong value with this code.

    int fileno1=Integer.parseInt(Result.getString(2));
    int increment = ++fileno1;
    String convertno1=String.valueOf(increment);
    filenotxtfield.setText(convertno1);

    If 1 and 2 file no already exists after entering 3rd number manually and then save it ,it is showing me 2 not 4.?

    Java tutorial question

  • How to make Integer number increment by 1 in a JTextField?
    C chdboy

    thanks for the Idea I'm working on it. EDIT: I managed to do what I wanted BUT... It only happens till the application is open and I'm saving data one after one...as soon as I close to application and opens in again I have see the last file no and enter the next file no manually. with this code

    String filenostr = filenotxtfield.getText();
    statement.setString(1,filenostr);
    int fileno=Integer.parseInt(filenostr);

    fileno++;

    	   String convertno=String.valueOf(fileno);
    	    filenotxtfield.setText(convertno);
    	statement.executeUpdate();
    	
    	int rowsAffected = statement.executeUpdate();
    	if(rowsAffected > 0) 
    	{
    		   JOptionPane.showMessageDialog(null, "Data Inserted successfully!");
    		}
    		else
    		{
    		    JOptionPane.showMessageDialog(null, "Data is not Inserted!", "Not successfully", JOptionPane.ERROR\_MESSAGE);
    		}
    	statement.close();
    	con.close();
    

    Addition to that I'm getting error on line

    int rowsAffected = statement.executeUpdate();

    ERROR:

    com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK__Employer__6F09E6800F975522'. Cannot insert duplicate key in object 'dbo.Employer'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:314)

    But as I see in my Management Studio that the data has been saved.but still getting this error ..why?

    Java tutorial question

  • How to make Integer number increment by 1 in a JTextField?
    C chdboy

    I have a form in which I have made File no field which hold the Integer value like 1-2-3-4 and so on. I want that ,when I save a form which has file no 1 ,and then after when I want to save the next record it should remember the last file no and increment by 1. I have not coded yet anything because I don't know if it is possible?

    Java tutorial question

  • JSpinner value from Database.
    C chdboy

    I have this code which saves the value into database from JSpinner

    SpinnerListModel monthModel = new SpinnerListModel();
    String[] monthStrings = {"1Month","3Month","6Month","1Year"}; //get month names
    monthModel = new SpinnerListModel(monthStrings);
    JSpinner spinner = new JSpinner(monthModel);
    statement.setString(28,(String)monthModel.getValue().toString().toUpperCase());

    But how to get that value back for Editing? I tried

    spinner.setText((String)monthModel.getValue(),29);

    But it says

    The method setText(String, int) is undefined for the type JSpinner

    How do I get the values from Database?again to JSpinner.

    Java question database tutorial

  • Navigationa with ResultSet
    C chdboy

    Thanks for the Idea. :)

    Java database help

  • Navigationa with ResultSet
    C chdboy

    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.

    Java database help

  • Putting a split String in a printout.
    C chdboy

    thanks a lot :)

    Java graphics help question

  • Putting a split String in a printout.
    C chdboy

    String[] str1 = companyinforstring.split(":");
    for(int i=0;i

    Is there any simple way of doing it?
    Please let me know

    Java graphics help question

  • Putting a split String in a printout.
    C chdboy

    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?

    Java graphics help question

  • Something is wrong with the print command.
    C chdboy

    I have got the solution I have created two Printer Job 1.

    PrinterJob job = PrinterJob.getPrinterJob();
    
    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.

    Java graphics debugging career

  • Something is wrong with the print command.
    C chdboy

    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?

    Java graphics debugging career

  • Something is wrong with the print command.
    C chdboy

    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;
    }
    // User (0,0) is typically outside the
    // imageable area, so we must translate
    // by the X and Y values in the PageFormat
    // to avoid clipping.
    Graphics2D g2d = (Graphics2D)graphics;
    /\*Rectangle2D.Double rectangle = new Rectangle2D.Double ();
    rectangle.setRect (pageFormat.getImageableX () + 72,
    pageFormat.getImageableY () + 72,
    72,
    72);
    g2d.draw (rectangle);\*/
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    // Now we perform our rendering
    graphics.drawString("Hello world!", 100, 100);
    // tell the caller that this page is part
    // of the printed document
    return PAGE\_EXISTS;
    // TODO Auto-generated method stub
    }
    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!!!!");
    }
    }
    }
    }
    
    Java graphics debugging career
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups