n3red Light Poster

I find this like really really strange for quit a few reasons. For me the most productive time to program is after 21:00 hours. The weird part is this even if i sleep like a baby and i come to work i will be productive but not nearly as productive and INTO programming as i am after dark : P

The weird thing is even if i come from work and school so tired i can barely keep my eye's open if i will sit down behind a screen i will suddenly change moods from tired to like freaky focused.

Night seems to go really well in hand whit programmer, anyone else effected by this whatever it is xD

n3red Light Poster

Hi,

I it possible to implement an ActionListener to a global or local variable so that if variable changes the Listener performed a certain function / method etc..

I am working on a GUI application i am guessing there has to be a better solution than wrapping my main code in a forever loop is there ?

Oke so this is my code so far it works well but there is a small problem, the arraylist and the function removeModule do not work correctly.

function removeModule does actually remove the node from the tree on GUI when displayed but not from the actual ArrayList because when i add one module back to that ArrayList the one that was so-pose to be removed is still in the list and will reappear.

[CODE] ArrayList nodes = new ArrayList();

public void addModule(final JTree module_browser, final JTree selected_modules){
    module_browser.addTreeSelectionListener(new TreeSelectionListener(){
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode(module_browser.getLastSelectedPathComponent());
            nodes.add(node);
            updateModules(selected_modules);
        }

    });
}

public void removeModule(final JTree selected_modules){
    selected_modules.addTreeSelectionListener(new TreeSelectionListener(){

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode(selected_modules.getLastSelectedPathComponent());
            parseNodes(node);
            updateModules(selected_modules);
        }
    });
}

public void parseNodes(final DefaultMutableTreeNode node){
    for(int i = 0; i < nodes.size(); i++){
        if(nodes.get(i) == node){
            nodes.remove(i);
        }
    }
}

public void updateModules(final JTree selected_modules){
    //selected_modules.setModel(new DefaultTreeModel(nodes));
    DefaultMutableTreeNode hiracy = new DefaultMutableTreeNode("Selected Modules");
    for(int i = 0; i < nodes.size(); i++){
        hiracy.add(nodes.get(i));
    }
    selected_modules.setModel(new DefaultTreeModel(hiracy));
}[/CODE]

Oke so to dismiss the post above i found a solution by creating a neutral TreeNodes than appending those to new tree via model.

Now i want to know is it possible to have a DefaultMutableTreeNode Table like:
DefaultMutableTreeNode[] nodes = DefaultMutableTreeNode();

Its really simple but i dont know how to implement this.

Anyways if anyone gets an idea how to get around this here is what i am trying to do:

1) I have a separate GUI class and a separate Logic class
2) I have 2 JTree components A and B
3) Once a user clicks on a node on A i want that node to be appended to B
4) I am using function bellow to call both JTree components and i am listening for node selection on JTree A once i click on one i wish to add it to B.

5) B already has 1 root node defined inside another class

Both of these 2 threes are created in a separate class. I wish to add nodes from one to another in this function whats the best way i can deal whit this.

Hm the thing is that that JTree B that i am adding the node to already has a Node root node attached to it but in another package/class

[CODE]Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: javax.swing.JTree.add
at pft.controller.Tower_Controller$2.valueChanged(Tower_Controller.java:59)
at javax.swing.JTree.fireValueChanged(JTree.java:2917)
at javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:3376)
at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:634)
at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1092)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:293)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:187)
at javax.swing.JTree.setSelectionPath(JTree.java:1631)
at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2371)
at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3587)
at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:3526)
at java.awt.Component.processMouseEvent(Component.java:6501)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)[/CODE]

n3red Light Poster

Hi,

I have 2 JTree components on my JForm. If a user clicks on a DefaultMutableTreeNode on JTree A i want app to add it to JTree B.

[CODE]
public void addModule(final JTree a, final JTree b){
a.addTreeSelectionListener(new TreeSelectionListener(){
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(a.getLastSelectedPathComponent());
b.add(node);
}

    });
}

[/CODE]

I have been trying to implement this via MouseListener or TreeSelectionListener but
just cant do it right problem occurs at this location ( b.add(node); );

n3red Light Poster

I have been testing out the component JProgressBar, now from what i learned so far
it's easy to handle but any way i try it i cannot get it to work.

To explain: I want to have a JProgressBar component that will show the total and consumed amount of oil. | 5000 / 12943 |

I am writing a simulator for oil distribution over a pre defined pipeline and this pipeline can handle 1000 total liters in flow. Now to the pipe line i can add choke points that control how much of oil can flow. Now if i add 1 button to the pipeline that would be 126 / 1000 and i want my jprogressbar to show that instead of a % amount. And if i add another choke point it goes up 252 / 1000 etc until 1000.

I am getting really sleepy so i may just be overlooking something in JProgressBar or it truly cant be implement whit that component in that case can anyone suggest a decent alternative to SWING that can implement this.

I have never undertaken a larger project at most for the sake of good looking code i had 3 maybe 4 classes.

n3red Light Poster

Hello,

To get right to the point i would like to ask for some suggestions regarding writing Java
GUI applications.

I have so far only done small GUI or Console applications that consisted of max 2 classes aka. 2 files. But now while back i decided to take on a larger project. I find it difficult to separate Logic and GUI part of the application. I wish to keep my GUI and my Logic separate so i can have some sort of organization. Unless the application is really small in scale i don't like to keep my event listeners all in a same file or class.

Can anyone point out some guides on "how-to" coding Java GUI or give tips on how to keep it all clean.

n3red Light Poster

Hi,

I am using eclipse and Netbeans 7 whit Java JDK 1.6
i am wondering how do i add java extensions.

I want to add Appache libary : org.commons.apache.2.4.jar
to my java because their libary offers a lot of good
extensions such as coutnMatches method.

n3red Light Poster

Hi, i am still learning i want to make a simple shell script.
I wish to make a function that will receive 2 arguments (two dates) and will return
all users who logged in during that period, how many times and how long were
they logged in.

I wish to call my function this way: ./functionName 29/05 30/05

This would print out all users that were logged in during that period
how many times did they login and how long were they logged in.

Result would be maybe like: username 5x 0 days 12:43

How can i go about this, thanks in advance.

I have tried opening a notepad and writing something but i just
get confused on every step.

I am used to writing functions they way they are in C, Python, Java, PHP, Ruby
but here it seems its all sick and twisted.

I have read up so far that i should be taking info out of wtmp file can someone
give me few more pointers.

n3red Light Poster

Hello,

First of all let me say i have very little idea about shell scripting
and linux ( ubuntu ).

I am trying to write a script where i would give it two arguments two dates
in a 29/5 30/5 whitin the console and it would return a list or it out print out
users that were logine'd within that time and for how long and how many times
did they login.

n3red Light Poster

Hi,

i know how to open a file and read data from it
but i wanna print out the number of lines in that file ?

How would i go about this ?

Thanks for help guys substring() worked . xD i love u

n3red Light Poster

I wanna know how to print only part of a string.
For instance:

[CODE]
public static void main(String[] args){

   String a = "daniweb.com";
   System.out.println(a);

}
[/CODE]

I wanna say print only characters after the 4th one
so the output would be:

[CODE]> web.com[/CODE]

n3red Light Poster

Hi,

I am writing a simple script, basicly i have:

[CODE]
String s = "A quick fox jumps over a lazy dog";
[/CODE]

Now i want to print it like this: (like 3 words per line) ::

A quick fox
jumps over a
lazy dog

Know i know i can move the string aka the line to a array and then looping
over it whit a "for" or "while".

But is there any way i can avoid using a array maybe do it whit just
one for or while loop.

Thanks in advance,
n3red

Can someone take a looka at the last printf and tell me why can i print out
my value.
[CODE]struct voznja beriVoznje(char datoteka){
FILE open;
open = fopen(datoteka,"r");
while(!feof(open)){
struct voznja
drive;
drive = (struct voznja*) malloc(sizeof(struct voznja));
fscanf(open, "%d", &drive->id);
fscanf(open,"%s", drive->ime);
fscanf(open,"%s", drive->priimek);
fscanf(open,"%d", &drive->meritve);
//printf("%d", drive->id);
//printf("%s", drive->ime);
//printf("%s", drive->priimek);
//printf("%d", drive->meritve);
for (int i = 0; i <= drive -> meritve; i++){
fscanf(open,"%f", &drive->x[i]);
fscanf(open,"%f", &drive->y[i]);
printf("%f", drive->x[3]);

    }
}

}[/CODE]

n3red Light Poster

Hello,

Can someone please explain to me because i do not understand the
tutorials on pointers.

anyways i have a struct:

[CODE]
struct driver {
int id;
char name[30];
int runs;
}

//I am reading a file which goes in order ID NAME RUNS as: 1 Super Man 5
//I am reading it from a file like so:

struct drive read(char file){
int x = 1;
FILE open;
open = fopen(file,"r");
while(!feof(open)){
struct drive
drive1;
drive1 = (struct drive*) malloc(sizeof(struct drive));
drive1->stevilka=x;
fscanf(open, "%d", &drive1->id);
fscanf(open,"%s", drive1->name);
printf("%d", drive->id);
printf("%s", drive->ime);
}

}

[/CODE]

What am i doing wrong here ?

n3red Light Poster

I have Google'd and all i found was outdated, buggy or not working
source samples. Here is what i tried but i have a bit of a problem:

[CODE]void toDecimal(char bin[]){
int i, d = 0;
int l = strlen(bin)-1;
int x = 1;
for(i = 0; i < l; i++){
int a = (bin[i] - '0');
x = 2;
d = d + a
x;
//printf("%d",d); This will just print out 1222222
//printf("%d",x); This will just print out 1 2 4 8 16 ..
}
}

int main(){
toDecimal("10000001");

}[/CODE]

For anyone that may in future have this problem i have solved it the
for and if statements i did were correct thinking but i just did it a bit
wrong xD

Here is how you capitalize the first character of every word in a block of text
or a sentence etc:

[CODE]

char lines[300] or char lines = "some random text if its not feed'ed from a external file"

for(int i=0; lines[i]; i++){
if(isspace(lines[i-1])){
lines[i] = toupper(lines[i]);
}
}
[/CODE]

Tweeked the code but.. still having problems

Here is my code help xD

As you can see i successfully turn "char lines" in to lowercase characters the entire text. Now in second "for" statement i am trying to lookup each word in
"char lines" count back and if it eaquals "isspace" then go +1 character and
capitalize it. But iam getting a complile error.

Iam up to my 3rd coffe, why cant there just be a simple ucfirst function xD

Basically i need to write a function that will uppercase the first character.

[CODE]#include

include
include
include

int main(){

FILE *open;
open = fopen("vitranc.txt","r");

char lines[300];
//char tmp = '\0';

while(fgets(lines,300,open))
{

    for(int i=0; lines[i]; i++){
        if(lines[i-1]==isspace){
        lines[i] = toupper(lines[i]);
        }
    }

}
printf("\n\n");

fclose(open);

}

[/CODE]

[CODE]
for (i=0;i<theLength;i++)
theString[i] = toupper(theString[i]);

return 1;[/CODE]

Iam trying to count the word and when it comes to the first char turn in in to upper. Iam kinda a novice this would be much easier in python and php xD

[CODE] topper(*string);

for( ; *string != '\0'; string++)
{

if(temp == ' ')
toupper(*string);

temp = *string;
}[/CODE]
n3red Light Poster

Hi,

I have a small problem after working on my program last night i found out
that C does not have any function that uppercase first character in a word.

So i have been trying to split each word in to characters and uppercase the first
word but it keeps replacing the first character whit a whitespace

It there any other way around this ?

[QUOTE=abhimanipal;1502332]Some of the functions you might need

strtok --> Use this function to split a string into a series of words
strcmp --> Check if this word is a name or a period[/QUOTE]

Thanks that helped a lot

n3red Light Poster

So here is my code:
The purpose of this code is to take all the plain text in all capital letters in
the vitranc.txt file and turn them all in to lowercase characters.

Now to my knowledge i can do this with "tolower" function but:
when i add tolower in my "while" counter it does not compile but gives an error
about some conversion from char to int.

Now in addition i have also tried turning the "lists" to int whit "atoi" method before
passing it on to "tolower" and it works but not as it should only few words get turned
to lowercase but most remain uppercase.

[CODE]

include
include
include
include

int main(){

FILE *open;
open = fopen("vitranc.txt","r");

char lines[300];

while(!feof(open)){
    fgets(lines,300,open);
    lines = tolower(atoi(lines));
        printf("%s",lines);
}
printf("\n\n");

fclose(open);

}
[/CODE]

Instead of a while counter i have tried a "for" expression in this way:

[CODE]
char lines[300];
int i;

for(i=0;lines[i],i++){
lines[i] = tolower(lines[i]);
printf("%s",lines);
}
[/CODE]

Can u follow up whit a code example