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
  1. Home
  2. General Programming
  3. Java
  4. Java code Convert to C#

Java code Convert to C#

Scheduled Pinned Locked Moved Java
csharpjavahelpquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LAPEC
    wrote on last edited by
    #1

    Hello Everyone I'm trying to convert this java code to C#, could someone please help me on this because I am very new into programming. Here is the Java code...

    import java.awt.Component;

    import javax.swing.JOptionPane;

    public class ConfirmDeleteDialog {
    public static final int YES = JOptionPane.YES_OPTION;
    public static final int NO = JOptionPane.NO_OPTION;
    public static final int CANCEL = JOptionPane.CANCEL_OPTION;
    static final int OK = JOptionPane.OK_OPTION;
    static final int CLOSED = JOptionPane.CLOSED_OPTION;

    public static int showMessage(Component parent, String message, String title) {
    	return JOptionPane.showConfirmDialog(parent, message, title, JOptionPane.YES\_NO\_OPTION, JOptionPane.QUESTION\_MESSAGE);
    }
    

    }

    thanks in advance lapeci

    B L D 3 Replies Last reply
    0
    • L LAPEC

      Hello Everyone I'm trying to convert this java code to C#, could someone please help me on this because I am very new into programming. Here is the Java code...

      import java.awt.Component;

      import javax.swing.JOptionPane;

      public class ConfirmDeleteDialog {
      public static final int YES = JOptionPane.YES_OPTION;
      public static final int NO = JOptionPane.NO_OPTION;
      public static final int CANCEL = JOptionPane.CANCEL_OPTION;
      static final int OK = JOptionPane.OK_OPTION;
      static final int CLOSED = JOptionPane.CLOSED_OPTION;

      public static int showMessage(Component parent, String message, String title) {
      	return JOptionPane.showConfirmDialog(parent, message, title, JOptionPane.YES\_NO\_OPTION, JOptionPane.QUESTION\_MESSAGE);
      }
      

      }

      thanks in advance lapeci

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      That seems to be a custom message box. Hence in C# (if you are using Windows Forms), you could use MessageBox.Show as a replacement for ConfirmDeleteDialog.showMessage. The return value in C# is a DialogResult.

      L 1 Reply Last reply
      0
      • L LAPEC

        Hello Everyone I'm trying to convert this java code to C#, could someone please help me on this because I am very new into programming. Here is the Java code...

        import java.awt.Component;

        import javax.swing.JOptionPane;

        public class ConfirmDeleteDialog {
        public static final int YES = JOptionPane.YES_OPTION;
        public static final int NO = JOptionPane.NO_OPTION;
        public static final int CANCEL = JOptionPane.CANCEL_OPTION;
        static final int OK = JOptionPane.OK_OPTION;
        static final int CLOSED = JOptionPane.CLOSED_OPTION;

        public static int showMessage(Component parent, String message, String title) {
        	return JOptionPane.showConfirmDialog(parent, message, title, JOptionPane.YES\_NO\_OPTION, JOptionPane.QUESTION\_MESSAGE);
        }
        

        }

        thanks in advance lapeci

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        There is no simple equivalent of this in C# as it refers to Java specific components. It would be better if you started with Windows forms[^] in C# and build your program from scratch.

        One of these days I'm going to think of a really clever signature.

        1 Reply Last reply
        0
        • B Bernhard Hiller

          That seems to be a custom message box. Hence in C# (if you are using Windows Forms), you could use MessageBox.Show as a replacement for ConfirmDeleteDialog.showMessage. The return value in C# is a DialogResult.

          L Offline
          L Offline
          LAPEC
          wrote on last edited by
          #4

          Hi Bernhard Hiller Thanks for replaying to my java question. I'm using WPF Window Form (not the Windows Forms). Is there anyway you could help me to convert that java code I'm very new to programming and I don't have a clue how to do it honestly... Kind Regards lapeci

          B L 2 Replies Last reply
          0
          • L LAPEC

            Hi Bernhard Hiller Thanks for replaying to my java question. I'm using WPF Window Form (not the Windows Forms). Is there anyway you could help me to convert that java code I'm very new to programming and I don't have a clue how to do it honestly... Kind Regards lapeci

            B Offline
            B Offline
            Blikkies
            wrote on last edited by
            #5

            What are you trying to do?

            1 Reply Last reply
            0
            • L LAPEC

              Hi Bernhard Hiller Thanks for replaying to my java question. I'm using WPF Window Form (not the Windows Forms). Is there anyway you could help me to convert that java code I'm very new to programming and I don't have a clue how to do it honestly... Kind Regards lapeci

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              If you are new to programming then why are you concerned about trying to convert Java to C# when creating a WPF program? Forget Java and spend some time studying how to do things properly in WPF. There are lots of useful samples in the WPF articles section[^].

              One of these days I'm going to think of a really clever signature.

              1 Reply Last reply
              0
              • L LAPEC

                Hello Everyone I'm trying to convert this java code to C#, could someone please help me on this because I am very new into programming. Here is the Java code...

                import java.awt.Component;

                import javax.swing.JOptionPane;

                public class ConfirmDeleteDialog {
                public static final int YES = JOptionPane.YES_OPTION;
                public static final int NO = JOptionPane.NO_OPTION;
                public static final int CANCEL = JOptionPane.CANCEL_OPTION;
                static final int OK = JOptionPane.OK_OPTION;
                static final int CLOSED = JOptionPane.CLOSED_OPTION;

                public static int showMessage(Component parent, String message, String title) {
                	return JOptionPane.showConfirmDialog(parent, message, title, JOptionPane.YES\_NO\_OPTION, JOptionPane.QUESTION\_MESSAGE);
                }
                

                }

                thanks in advance lapeci

                D Offline
                D Offline
                Dave Doknjas
                wrote on last edited by
                #7

                It can almost be completely converted to C#:

                using System.Windows.Forms;

                public class ConfirmDeleteDialog
                {
                public static readonly int YES = DialogResult.Yes;
                public static readonly int NO = DialogResult.No;
                public static readonly int CANCEL = DialogResult.Cancel;
                internal static readonly int OK = DialogResult.OK;
                internal static readonly int CLOSED = JOptionPane.CLOSED_OPTION; //no equivalent to 'CLOSED_OPTION'

                public static int showMessage(Component parent, string message, string title)
                {
                	return MessageBox.Show(parent, message, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                }
                

                }

                Dave Doknjas Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

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