|
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;
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
|
|
|
|
|
need coding of tower of hanoi game in java(netbeans) .......!!!
|
|
|
|
|
Then please go and search[^] for it. Do not expect other people to do your work for you.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Java(netbeans) does not exist.
There is Java SE[^], which you probably meant, and there is a IDE called Netbeans[^](beside of Eclipse[^] ).
The Tower of Hanoi[^] is a common puzzle. You will find an animation on the right side of the wikipedia page - check that one out and find a code to describe it.
EDIT The text is also not bad - pretty good described what's going on.
|
|
|
|
|
|
class Matrix{
public static void main(String []args){
int ArrayMatrix [] [] = {
{1,0,0,0,0},
{0,1,0,0,0},
{0,0,1,0,0},
{0,0,0,1,0},
{0,0,0,0,1},
};
int l = ArrayMatrix.length;
int i,j;
boolean a=true;
boolean b=false;
for( i=0;i<l;i++)
{
for(j=0;j<l;j++)
{
System.out.print(ArrayMatrix[i][j]+" ");
}
System.out.println("");
}
System.out.println("\n Array is Unit Matrix");
}
}
Asad Ali Jogi
modified 12-Nov-12 1:43am.
|
|
|
|
|
I assume you do not get it to work.
As this looks much like a homework, I'll give you some tips but no solution.
read them, follow them and you'll find the right way:
- variable names always start with lower case
always. ALWAYS. Please rename "ArrayMatrix" to "iArrayMatrix". Copy it and set up a second Array for testing.
You can comment them in/out by using Strg+7 in any IDE.
- use clear names
"i" and "j" are common counters. But how about "iRow" and "iCol" ? Those give you much more control on what is happening.
- delete "l"
No. One does not put the length of an Array in a variable. Simply NO.
- I think this homework is about recursion. Read about that on the web. That would need some methods - is this topic already introduced in class? can we use some?
- one boolean "bIsMatrix" should be enough. give it a init value "false" and use the loops to set it to true when you find a value "1" in the diagonal. Set it "false" if not. Read "bIsMatrix" after the loops to present result.
|
|
|
|
|
That's not the complete rule for an identity matrix. The complete rule is that the matrix contains only 1s on the leading diagonal.
Don't hand this in, your teacher won't like the code style, but ...
boolean isIdentity(int[][] m) {
boolean isIdentity = true;
for(int i = 0; i < m.length; i++) for(j = 0; j < m[i].length; j++)
isIdentity &= m[i][j] == (i == j ? 1 : 0);
return isIdentity;
}
... I need to get my crazy coding instincts out in a controlled environment now and then
|
|
|
|
|
I want to show ImageIcon by adding to Label, but it has error, help me?
<pre lang="java">import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import java.util.Scanner;
class CatchTheRat extends JFrame
{
// The Rat
JLabel lb;
// Move it randomly!
Random r;
public CatchTheRat(int k)
{
// Set frame properties
setTitle("Catch The Rat");
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
// Set the background (just for a good look)
setContentPane(new JLabel(new ImageIcon("background.jpg")));
// Set layout to the content pane
getContentPane().setLayout(new FlowLayout());
// Create the rat
lb=new JLabel(new ImageIcon("rat.jpg"));
// Add the rat
getContentPane().add(lb);
// Create Random object
r=new Random();
// Create a timer and call it for every k seconds
new Timer(k,new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
// Move the rat randomly, subtract 75, so that the rat should not meet the edges
lb.setLocation(r.nextInt(getWidth()-75),r.nextInt(getHeight()-75));
}
}).start();
// Add mouselistener, notify when user clicks it!
lb.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me)
{
// Create a beep sound when clicked to notify
Toolkit.getDefaultToolkit().beep();
// Also print it!
System.out.println("Caught!");
}
});
// Maximize the frame
setExtendedState(MAXIMIZED_BOTH);
}
public static void main(String args[])
{
// Create Scanner object
Scanner s=new Scanner(System.in);
// Let the user enter his capability of catching the rat!
System.out.println("Enter the speed");
// Read the input
int k=s.nextInt();
// Create the frame and send the value of k
new CatchTheRat(k);
}
}
</pre>
|
|
|
|
|
- Please fix your formatting.
- Which line has the error?
- What error?
Note, we cannot see your screen or guess what problems you are seeing.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
It's called OOP for a reason. Please, the constructor never executes code. Define some methods for that.
You are adding the JLabel to the ContentPane - which you first set with a JLabel. Adding a JLabel to a JLabel does not work.
Also please just refer to the JFrame by adding to "this".
Suggestion:
1. OOP that.
2. Set up a JPanel, that forms the playground for the rat.
You probably want a second Panel for the Game controls - which are now to be entered in the console before.
3. Use a null-Layout for the game-Panel. You want to move the rat by pixel / absolute position, not by relative position to some other control.
FlowLayout is also default, does not need to be initalized.
import javax.swing.*;
class CatchTheRat extends JFrame {
JLabel lb;
Random r;
public CatchTheRat(int k) {
createGUI(k);
}
private void createGUI(int k) {
setTitle("Catch The Rat");
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(new Dimension(800,600));
this.add(createContent(k));
setVisible(true);
}
private JPanel createContent(int k) {
JPanel oPanel = new JPanel();
lb = new JLabel(new ImageIcon("rat.jpg"));
oPanel.add(lb);
r = new Random();
lb.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
Toolkit.getDefaultToolkit().beep();
System.out.println("Caught!");
}
});
return oPanel;
}
public static void main(String args[]) {
new CatchTheRat(5);
}
}
|
|
|
|
|
Thanks for the suggestion. But that worked in my system. We can add JLabel to another JLabel because JComponent itself is a container and we can add any component to any component. There is no limitation. The add method does it.
Gowtham Gutha (http://java-demos.blogspot.com)
|
|
|
|
|
Technically - yes. Until someone wants to place place a text in the JLabel or plays around.
So it's pretty much safer to use a JPanel, that is known as a container.
|
|
|
|
|
Ok. By the way, could i also know why it is not recommended to write code in the constructor and only in a separate method and then call that method?
Gowtham Gutha (http://java-demos.blogspot.com)
|
|
|
|
|
|
What really is the error in my program? I couldn't understand. You'll need to have those image files (the background and the rat) to see them. That may be the possible error because it has worked in my development environment.
Gowtham Gutha (http://java-demos.blogspot.com)
|
|
|
|
|
Hi
i am new in android development, my question is how to obtain data from Mysql(questions) server PHP to the tablet, i know that with web service but how, and display automatic in the activity (texview?????) questions for example 5 cuestions for screen and other 5 for the next screen automatic.please give me a page or site where i find this information
sorry for my bad english, i hope understand, and i beginning in this develop of apps
thank you for your answers
see you
|
|
|
|
|
I‘ve used C# for one and half years.
Recently,for job reason,I need to use Java.
Actually,I've been learning WP Development,but it is hard to find a job,so I turn to android.
But they are lots of Java and Android books,so any recommend.
Beginner , Advanced Books.
|
|
|
|
|
Java in a Nutshell, published by O'Reilly.
The nutshell series are always good value.
A bit of introductory tutorial (more refresher, really) and then comprehensive reference.
So not a beginner's book but a working developer's constant companion.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
|
Herbert Schildt's Java The Complete Reference
Updated and Expanded for Java SE 7 will be of good choice.
|
|
|
|
|
Is it need to learn Java 7 just for android development?
|
|
|
|
|
You might not need if you have a grip on the basics of Java. If you have then you can go ahead referring android books.
Gowtham Gutha (http://java-demos.blogspot.com)
|
|
|
|
|
|