Antenka 274 Posting Whiz

Hi, hwoarang69.
I'm not able to test your code right now, but I'll take a shot to guess, where's the problem sits. It can be in this method:

public void actionPerformed(ActionEvent e)
{
    //all collsion stuff go in here
    repaint();
}

just check, how many times it been called every time when you perform an action.

Take a look a these few links .. I guess, there're some good info and examples:
Java applets
CA597 Tutorial - Simple Applets
javax.swing.Timer

Antenka 274 Posting Whiz

I just would like to add something about using methods.
You can easily break up your code into methods by simple describing what it does. E.g. "Method takes user input and makes a roll and builds a histogram ...". The activities, separated by "and" word may be easily moved into separate methods (see the link in the end of my post).
One method should be responsible for only 1 operation and it's name should describe it's behavior. If your method name looks like it's too long ... take a closer look, if it can be divided into a few.

Take a look at this article: Single responsibility principle

Antenka 274 Posting Whiz

Hi there!
I'm still under inspiration of reading one more book about good coding practices, so ... I just can't passy by quietly :)
I'd like to give a few notes about this thread:

First.

Programming is all about complexity management. So, if you have a task to make a 1-dimentional array with a sits 1-5 for an economy class and 6-10 for business, there's no need to try to guess all possible usages for your code. It can be way different from "11-seats plane". Why can't it be train ... with 3 classes. Same sits booking, but we have extra class and a few "fuselages". It's a simple book-assignment ... moreover, there're still a pretty big bunch of interesting topics, that isn't covered yet (including enums, complete information of class usages etc.) ... C'mon guys, hwo's ready to build up a commercial booking application using only 1-dimentional arrays with no classes and enums? ;)

Of course, in real-world programming, you should think of possible ways, but they're as usual must be
fully documented as your assignment. And you should code them maximally close to that wording.

It's just another side of medal. Haven't anyone faced such situation, when you ask "code me a method, which sum's a two numbers". A few days you hear nothing from developer. And then, on the 3rd day, you get a all-in-one method-calculator with a huge bunch of incoming parameters, indicating the operation, additional params etc. etc. ... isn't it funny? …

Antenka 274 Posting Whiz

You can take a look at the progs, that you usually use: different viewers, chat clients, Music/Video players, file managers, hardware utilities etc. etc. .. and make your own. With the functionality, that it's missing (well, actually about any prog you can say "It's a good one, but if it has <something>, it would be much better!" :D) .. so you have a chance to add this something and enjoy a perfect prog ;)

Antenka 274 Posting Whiz

That's really weird when your prog founds a 3d char in a 2-char string ;)

Antenka 274 Posting Whiz

Ok .. suppose, we have entered a text, that consists of 2 letters.
What would we have here:

for (int p = 0; p <= tbname.Text.Length; p++)

Here, we will iterate from 0 to 2, ie:
we will take tbname.Text[0], tbname.Text[1], tbname.Text[2] .. doesn't look weird for you? :)
Try it yourself: enter 2 letters and debug this thing. And post here your original string and the thing that you have under tbname.Text[2].

A magician never tells

I just want you to find your solution by yourself .. I'm just trying to lead you in a right direction ;)

but still not working

Try the thing, that I said upper in this post. Fix a bug, if there is any .. and .. I'm waiting for your results ;)

Antenka 274 Posting Whiz

do you mean for the "ForeColor"?

Exactly. Know why? Because:

((int)(((byte)(60)))

it's the same as

60

Also, tbname.Text.Length + 1 . Why plus 1? Count how many times it would iterate if your string would be, e.g. 2 symbols length.

It doesnt pick up when a number is entered and it doesnt do anything when a number isnt entered. I dont get it :\ this code just doesnt seem to work at all

Answer the previous question, cause it may throw an exceptions to you (I would be surprised, if it's not :)). That may be cause a problem.

P.S. Char.IsLetter(n) works pretty good in here, and determines a strings also as the others symbols.

Antenka 274 Posting Whiz

The scope of visibility of a j is between {} of you cycle. Because it was declared in the for-cycle.

You have 2 ways to go:
1. Move declaration to a higher level to extend the boundaries, where this variable can be visible.
2. Save the value of j variable in a different variable with a larger scope. And then work with it.

Antenka 274 Posting Whiz

Uhm .. owkey .. let's try to compose it. For example, you found a match in the element AddressBook[0,1], so you need to write the exact "AddressBook[0,1]".

Let's divide this string into 2 parts:
1. Static. Means that it would remain the same for each output: "AddressBook[", "," and "]".
2. Dynamic. Means that you have to obtain it's value each time: "i" and "j"

To concatenate your strings you use "+" sign.
The most interesting part is that you already have such combined output in your code, e.g. here:

Console.WriteLine("First Name: " + AddressBook[0, 0] + ". Last Name: " + AddressBook[0, 1] + ".");

Now, try to compose ... ;)

Antenka 274 Posting Whiz

What stops you from using your AddressBook , i , j variables to print the results? ;)

Antenka 274 Posting Whiz

:) Take a look at this discussion: How to search a string in String array. There're a few ways on how to achieve that (including collections).

Antenka 274 Posting Whiz

Is it a requirement to use an array (rather than a collection)?

Antenka 274 Posting Whiz

At first, Dns.GetHostAddresses means a few adresses (see MSDN). It returns an array.

The second is .. as MSDN says:

Dns.GetHostName Method
Gets the host name of the local computer.

Means that it will get the address of the machine, on which, this part of code was executed.
If you'd have a client part of your application on a different PC and run this code in the clients part - then it would return the address of that remote PC. But if you would run this code on a server, you'd always get the same result - name of a current machine.

Antenka 274 Posting Whiz

Hi, GonzR.
Here's a few points that may be helpful:
1. Char.IsLetter Method (Char).
2. Char.IsDigit Method (Char)
3. In C#, strings are char arrays, so there's no need to convert them. You can just iterate through string using any loop.
4. Also, there's an option to check your string, using regular expressions. Maybe it's too early, but still, here's a link: C# newbie: verifying that a string contains only letters.

Also, I would like to ask .. what magic are you doing with converting your numbers? :D Considering that the number literals in C# are treated as Int32 (or int) ...

Antenka 274 Posting Whiz

Agreed, my bad. Thanks for correcting :)

Antenka 274 Posting Whiz

Or something like this:

IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress address in addresses) {
    //for IPv4 .. if needed :)
    if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
        Console.WriteLine(address);
    }
}
Antenka 274 Posting Whiz
Antenka 274 Posting Whiz

Hello,
as MSDN says,

Control.Bounds Property: Gets or sets the size and location of the control including its nonclient elements, in pixels, relative to the parent control.

and

Control.Location Property: Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.

If you're ok with a Location, you probably should use it. If you need something more than upper corner coords - use Bounds :)

Antenka 274 Posting Whiz

As far as I know, the code in VB may be replaced with a similar code in C#. But, I doubt if playing with font size is a handy idea. Dunno about others, but I, personally, look cautious at web elements, who are living with their own life =) E.g. changing it's size or placement, so I need to wait till the "magic" would finish and then try continue to work.

It's just MHO .. and maybe in your case it's needed, but I decided to share my concerns :)

P.S. Here's what I've found in C#: C# Tutorial - Font Scaling

Antenka 274 Posting Whiz

Hello.
How about using something like:

this.Controls[i].Enabled = !this.Controls[i].Enabled;

To change the state in both ways.

Antenka 274 Posting Whiz

> if the user does change this to C:\newpdflocation\
> the next time the user opens the app, the location will be C:\pdfs\ right?
Depends on how app determines the default path to save your pdf's.
If, you write this setting in a config-file, or a property-file when user changes the default path. And then you restore this setting on application start up. Then the new path would be loaded

Antenka 274 Posting Whiz

> i'm using so i know which index was selected, so the app knows which file to open..
ok, how about:

int index = listBox1.SelectedIndex;
if (index >= 0) {
}

SelectedIndex property is 0-based. So if user selects any item in list box, it would return the selected index. If nothing selected - it will return -1. IMO, this approach:
1. More readable.
2. Less complex.
3. More appropriate for this situation.
4. And, I suppose, has performance advantages (if not dig too deep: SelectedIndex - is a property, than returns a single value, stored in a listBox; IndexFromPoint - is a method that calculates a selected item index based on where user clicked. Sounds like it has more work to do ;)).

> will the path set by the user always reset to the original path, or will it be the path the user updates

Not sure, that I understand you correctly. But I'll take a shot :) You mean, if the Location of Documents would be changed?
If so - I suppose, you should treat your "My Documents" (in a folder browse dialog) as a shortcut. If user would change the folder, assigned to this shortcut - you'll see the contents of a newly-assigned folder.

If you need to remember the previous-opened location - sure, you can write it in a property-file. And then, for example, make a button "Recent Documents" to view it's content.

Antenka 274 Posting Whiz

Is this is that you're looking for: Microsoft HTML Help 1.4 SDK? :)

Antenka 274 Posting Whiz

Hello, walid86.
Firstly, try it out by yourself:
1. Find your local folder called "My Documents".
2. Right-click on it and go to tab "Location".
3. See what's in there ;)

Next, it would be great if you posted exception message (so I don't need to recreate all the behavior to reproduce your exception), cause Win32 Exception is too generalized term.

Ok, closer to your exception. I have a few questions:
1. Where do you get it? (exact line of code)
2. What data is in variables, on that line?
3. What's this for:

int index = this.listBox1.IndexFromPoint(e.Location);
if (index != System.Windows.Forms.ListBox.NoMatches)

it's look like it should be

if (listBox1.SelectedItem != null) {
}

or

if (listBox1.SelectedIndex >= 0) {
}

.. but that's just a thoughts in a loud .. maybe there's something that making you use IndexFromPoint .

Antenka 274 Posting Whiz

Hello, wcroome.
I've created a Test Application, and when I add Items to lBFirmware , rather than lBoxTest1 , I'm able to obtain the selected Index in the specified handler:

private void lBFirmware_SelectedIndexChanged(object sender, EventArgs e) {
     ListBox lb = sender as ListBox;
     int selectedIndex = lb.SelectedIndex; //all ok here ;)
}
Antenka 274 Posting Whiz

Hi, adobe71.
C# uses the backslash to escape characters, so "\\" is equal to \ literal, and "\" results in error, because you trying to escape the second quote and your string literal remains "unclosed".

You have 2 ways to go:
1. As you can see, double backslash results in a single one. So, to have \ ? you have to write \\ . 4 backslashes to result "\\" .. and so on.

2. You can use @ before your string literal, so the compiler won't try to get the control sequences from your string (based on the backslashes) and would treat your string same, as you write it (so the @"\" results into \ ).

ddanbe commented: Good advice! +14
Antenka 274 Posting Whiz

Momerath, thanks for correcting.
Probably, shouldn't multitask while posting :D

NewOrder commented: thanks for the help +0
Antenka 274 Posting Whiz

Hello, here's where your problem sits:
1. You define and array of interfaces

IchecherMove[ , ] checker

2. Then instantiate your array using Checker class

new Checker[9 , 9];

don't see the problem yet? :) ok, continuing ..

3. You're inserting some variables into it, including this:

checker[5, 8] = new King("BK");

So what the problem is .. when you define an array of interface type and instantiate it by derived class - everything is seems to be good (since the Chacker class is easily automatically can be converted to IchecherMove). But if you said, that your array would contain a King instance - it's arguing with you, since King can't be implicitly converted to Chacker (as you said at instantiation time).

this change might resolve the error:

IchecherMove[ , ] checker = new IchecherMove[9 , 9];

but you cannot instantiate interfaces. So we need some workaround .. as a way, I can suggest you to use List<T> :

//for 1-dimentional
List<ISomeInterface> list = new List<ISomeInterface>();

//and for 2-dimentional
List<List<ISomeInterface>> list = new List<List<ISomeInterface>>();

then to instantiate 1 row ..

list.Add(new List<ISomeInterface>());

and to add elements to this row ..

list[0].Add(new SomeClass());
//and
ist[0].Add(new SomeOtherClass());

where, ofcourse

class SomeClass:ISomeInterface{
}
	
class SomeOtherClass:ISomeInterface{
}

Good luck :)

Antenka 274 Posting Whiz

Exactly!
I was suggesting you to be a kinda photographer .. you're arranging the objects in some manner, then taking a shot, then making some permanent changes to your scene and making another shot. Good job! :)

Antenka 274 Posting Whiz

Hello,
yeah, static word might be confusing for some time. But it's not that hard .. Static members has a class level, rather then object one. To understand it better, let's look at example. Imagine a form for making cookies ..

Your form is your class. And your cookies are your objects.
If you change your form once, it would affect all the children .. so the line:

color = colorParam;

means "May all MyRectangle objects would have a given color" .. all the objects, no matter if they were created before or after this call (of course, this for the case, when the color variable is static).

Ok, and now, correct your code, knowing all this .. or ask if something left unclear :)

ddanbe commented: He! Nice explanation :) +8
kvprajapati commented: Helpful! +11
Antenka 274 Posting Whiz

> So is there a way to link from html into the database to display the image onto a page?
I don't know, if we're talking about same linking, but if you can have a template for an HTML-page and populate it with data from DataBase, when it's needed.

> Are you saying that i can prevent that somehow?
I wasn't doing this by my own, but I saw some time ago .. they people was looking the way to work with a PrintScreen button and image, that it makes (they were going to fill with a some color areas, which they want to hide .. or change the pic's). Anyway, that's a starting point for you - you may check it whenever you want at Google ;)

> You ended that sentence a little weird i dont know what you meant.
I just said that, cause you want to prevent all possible preventable ways of stealing image .. so I added my 2 cents to your list :)

Antenka 274 Posting Whiz

Ok, one more try .. my browser is playing tricks on me today, so pleas don't mark it solved till I finish my answer :D

Ok, one more source for the errors might be, if you haven't specified a namespace for your class. Here's an example for you, where similar thingy is used: Data Binding in WPF.

P.S. I may be wrong, cause I have no tools to test this .. so this is just a wild guess :)

Antenka 274 Posting Whiz

The one way I see is storing the images in a DataBase .. that would prevent average user from searching images locally.

P.S. FYI, one more way of stealing images is just making a PrintScreen in a biggest possible resolution .. so, you might want to consider and this case ;)

Antenka 274 Posting Whiz

Ooops .. too late :)

Antenka 274 Posting Whiz

Ok, let's start from the beggining ...
The task is make a WPF application. What we usually expect from server - is performance. From client we usually expect usability, attractiveness, etc. (also performance, but less than from server). So it would be logical to make a server part of an application as Console application (as adatapost mentioned). And the client part would be a WPF application. So let's describe the basic behaviour for both parts:
Server:

  1. Start
  2. Waiting for the client to connect
  3. Process client
  4. Goto step 2 if we're going to proceed, and goto step 4 if we're done
  5. Stop the server

Client:

  1. Connect to the server
  2. Interact with server
  3. Close connection to not occupied server for too long

So now you should make 2 applications (the Console one and WPF one for the server and client respectively). I would suggest you to create them within one solution to ease the control of them.

Ok, now we have basic algorythm and 2 empty projects created. Now - closer to code .. I've changed a bit the client and server part .. Let's start from server:

static void Main(string[] args)
        {
            //The IP adress of computer, where server is running
            IPAddress ipAd = IPAddress.Parse("127.0.0.1");
            //Initialize listener on given IP and port
            TcpListener myList = new TcpListener(ipAd, 8001);
            //Start Listening at the specified port
            myList.Start();
            Console.WriteLine("The server is running at port 8001...");
            Console.WriteLine("The local End point is :" + myList.LocalEndpoint);

            //Endless …
kvprajapati commented: Greate Explanation. +9
Antenka 274 Posting Whiz

Hello,
to extract the value of your d variable into given string, you should:

  1. Close declaration of string with double quotes
  2. Concatenate the value of your variable with the rest of your string

Here's what I'm talking about:

"/c \"format " + d + " /fs:ntfs"
Antenka 274 Posting Whiz

Hello, I hope I understood you correctly ..
If you've started to talk about custom controls .. why not create a custom tab? Especially if you'll have an identical - looking tabs, I guess it would be a better way to create a sort of template. Here's an example to show what I'm talking about:
definition of a custom tab:

class CustomTab : TabPage
    {
        //just for example storing a link
        //to newly created texbox
        private TextBox _textBox;

        // a property to set a text 
        //for textBox
        public string BoxText
        {
            set { _textBox.Text = value; }
        }

        //creation of textBox on a Tab
        public void addTextBox()
        {
            TextBox tb = new TextBox();
            tb.Name = "tb" + Name;
            tb.Location = new Point(10, 10);
            tb.Parent = this;
            this.Controls.Add(tb);          
            _textBox = tb;
        }
    }

Ok, now we've encapsulated all the "magic" of creating and setting [inline]TextBox[/inline] inside the custom Tab class. This allows us to do such thing inside of main prog:

//creating a tab
CustomTab ct = new CustomTab();

... making some setups on Tab

//adding new TabPage to our tabControl
tabControl1.TabPages.Add(ct);

//adding a TextBox to our TabPage
ct.addTextBox();

... and maybe somewhere in other part of code (or from your example - on ButtonClick event):

private void button1_Click(object sender, EventArgs e)
{
   ((CustomTab)tabControl1.SelectedTab).BoxText = "Hi there";
}

This is just an example to start from .. you can place creation of the TextBox inside the constructor of CustomTab, or do whatever best passes your case.

Antenka 274 Posting Whiz

Hello,
I just want to share some thoughts to consider on your problem.

About suggested ways to go:

1. Leave it as it is it works but is inefficient

I think this solution has it rights to exist for the case when your collection has small size. But it isn't true for your case, so we're moving on. It would provide faster access to your data.

2. Create a 'master' defectcollection, preload it with all the defects and reference them

Well, same as for previous case - you can freely use it, when don't have too many data.

3. Write an defect collection that loads defects as required and allows multiple release objects to reference them

I think that is a step into right direction .. using less memory and still keeping it fast.

4. Write the defectCollection as a lazy collection populated only when it is referenced

I think it's the best of suggested solutions. Since your application isn't real-time system - you freely can make your user wait few more seconds (or even milliseconds) to load requested data. Moreover, if I were you - I categorized the defects on groups .. even made some structure of them to lessen the amount of information needed to load each time (also it can help to navigate between those defects). And place all this into e.g. lazy loading tree. (It can be whatever you want .. one more example would be a paged table, which loads …

kvprajapati commented: Good suggestion. Helpful. +9
Antenka 274 Posting Whiz

Hello.
I'm not sure if this is what you're looking for, but to get array of child forms, you can use the MdiChildren property, e.g.:

this.MdiChildren[0].BackColor = Color.Black;

//and in same manner for sub - sub child forms
this.MdiChildren[0].MdiChildren[1].BackColor = Color.Black;
Antenka 274 Posting Whiz

You're welcome .. please, mark this thread as solved if we're done with you problem :)

Antenka 274 Posting Whiz

Hello.
Dunno if it will suit your problem, but as an option - you could remove the header of the window. That's gonna help you to set the size to whatever you want.

Antenka 274 Posting Whiz

Ok, let's take an example:
137*1456

We can factorize it:
137*(1000 + 400 + 50 + 6)

To see the connection, we can convert this in form like this:
137*(1*10^3 + 4*10^2 + 5*10^1 + 6*10^0)
(where ^ means powering)

So, depending on the position of the digit in the number, we can represent it in such view (see above).

so, what we have:
137*1456=137*1*10^3 + 137*4*10^2 + 137*5*10^1 + 137*6*10^0

All you have to do now - is extract algorithm from this and code it :)

ddanbe commented: Clear explanation:) +5
Antenka 274 Posting Whiz

:) you're welcome. Good luck with your project!

Antenka 274 Posting Whiz

I understood you.

so in the loop i set the size of sum as ( sumsize -1 ) because in adding we add from right to left and the first added number will located in the most significant location of the array
and then at the end of the loop i decrement the sumzie to move left to the next location of the array, and because that the sum array is bigger that the longer number by ( 1 ) location , there will be a place to the carry at the least significant location.

That's pretty clear, but also, from your words: you go through arrays and their length is 1 less than sum array has. So the first element of this array would never be changed. So, that's why I gave you a piece of code, that assigns that first element (if necessary).

About this:

about the last point ( 1.
for(int i=0;i<sumsize;i++)
)i cant see anything wrong in it
i did this because i want to display the elements of the sum array which is still wrong

after previous cycle (where you sum your numbers) the value of sumsize would be 1 (in any case). So you would should do something like this:

for (int i = 0; i < sum.Length; i++)
Antenka 274 Posting Whiz

You're welcome .. please, mark this thread as Solved if your question is settled :)

Antenka 274 Posting Whiz

Hm .. hard to say ..

The selection appears as soon as your treeView get the focus. You can also play around TabIntex Property. If it's set to 0 (so your treView will be the first selected control on your form) then the node in it will be selected.

The other way to go would be - changing TabIntex so that treeView get's the input focus not in the first place.

But if I were you - I would choose the event-handling way .. in my opinion it gives more tangible control over treeView (but that's probably the question of comfort for developer :) ) So - you decide.

Antenka 274 Posting Whiz

Hello.
The troubles are starting here:

carry = 1;

You carry can be more than 1 .. so you should take the integer part of your holder:

carry = holder / 10;

Now, after summing all the numbers - you can still have something in your carry variable .. and shouldn't waste it:

if (carry != 0)
            {
                sum[0] = carry;
            }

And one more mistake, or rather typo:

for(int i=0;i<sumsize;i++)

You just were increasing sumsize in cycle... So it won't be the actual size of the sum.

sknake commented: excellent +6
Antenka 274 Posting Whiz

Hello.
Interesting question ..
I couldn't find any property or method for this case, but here's some workaround. You can process the BeforeSelect event and cancel it if the selection made e.g. not using mouse:

private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            if (e.Action != TreeViewAction.ByMouse)
            {
                e.Cancel = true;
            }
        }
Antenka 274 Posting Whiz

Hello, Ryshad :)
Ok, let's go .. I'll give a few comments on your suggestions and then give you an example.

a) include a flag in the bay to show that it is in another step

No, you shouldn't. Because the Bay class shouldn't be aware of what's happening outside of it.

b) have the step check with the sequence to see if any steps contain it

Also sounds a bit weird .. if rephrase - it would be "the element of an collection should be aware of other elements in collection "

c) check in the main form and pass a colour to the draw method

That's seems the right abstraction level for that design. The Form contains the collection and can be aware of what stored in it. But, probably not passing a color, but calling the right method or calling method with parameters.

Ok, for the first sight that all may seem kinda confusing, but here's example:
Imho, the one of the best methods of explanation - is use of metaphors...

Let's imagine that class is a closed box. If you're inside that box - you can't see what is happening outside (see your a suggestion).

But if we outside the box - we can see some of it characteristics (the methods or data, that you opened for public viewing aka open interface of the class).

Now let's put a few boxes in a row .. we have now a collection …

Geekitygeek commented: great explaination :) thank you +1
Antenka 274 Posting Whiz

Well, the other way could be storing datatable/data in your main form. And pass them to other forms of your application at creation time.