Violet_82 89 Posting Whiz in Training

Well, I had a look at it earlier on but I wasn't sure how that works, if this is what you're referring to http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyEvent.html
Reading that again now, you mean like numbers should be from VK_0 to VK_9 and letters from VK_A to VK_Z ?

Once I sort that out, is it possible to add the buttons to the row panels (assuming I have something like this

private JPanel row1;
private Jpanel row2;
private Jpanel row3;
private Jpanel row4;
private Jpanel row5;

) directly from within the Map declaration? SO, say, something like this:

mp.put(new Integer(xxx), row1.add(new JButton("~")));
...

thanks

Violet_82 89 Posting Whiz in Training

Get a book I'd say, so at least you learn some theory. I'm using Deitel and Deitel java how to program. Mine is based on Java 7. Not sure @JamesCherrill is particularly happy with my choice though, lol

Violet_82 89 Posting Whiz in Training

Ah OK, that's great, thanks :-)!

Violet_82 89 Posting Whiz in Training

OK cool. I thought I'd post a quick update.
I added a few elements, the labels and the textarea and then I got to the buttons. I followed your advice, well at least I attempted, look a bit more into Maps and hopefully created what you were expecting, a map containing the buttons as data but as for the key I used the integer keydown values, some found here https://msdn.microsoft.com/en-us/library/aa243025(v=vs.60).aspx and some here insteadhttp://www.west-wind.com/WestwindWebToolkit/samples/Ajax/html5andCss3/keycodechecker.aspx (I know it's for javascript but the codes seem to be the same.)
I haven't added anything to the GUI as yet except for the labels and the textArea and I thought let's check that the map is the way it should be before moving on.
If it is, the next thing would be to add the buttons and create the event handling presumably (interestingly if I add the import declarations

import java.awt.KeyListener;
import java.awt.KeyEvent;

without coding the event handling the application doesn't compile)

Code below:

 /*TouchType.java*/
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JLabel;
/* import java.awt.KeyListener;
import java.awt.KeyEvent; */
import javax.swing.JScrollPane;
//for the map
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeSet;   
public class TouchType extends JFrame{
    //private JPanel mainPanel;//wrapping panel
    private JPanel labelPanel;//panel for labels
    private JLabel label1;
    private JLabel label2;
    private JTextArea textArea;
    private BorderLayout bLayout1;
    private BorderLayout bLayout2;
    private GridLayout gridLayout;
    /*button declarations*/
    Map<Integer,Object> mp=new HashMap<Integer,Object>();//declaring a map object



    public TouchType(){//constructor
        super("Typing application");
        //mainPanel = new …
Violet_82 89 Posting Whiz in Training

OK, thanks Dani, hopefully you'll manage to change it :-)

Violet_82 89 Posting Whiz in Training

I suppose I said arrays because I didn't know any better, and I thought I could have one with chars and one with buttons to fill in with the chars and that would take only a few lines of code. But then I wouldn't know how to set the different sizes for the buttons.
I've never heard of Maps, so I checked them out and they're far ahead in the book, that's why I had no idea what they were :-). I've honestly got no idea how the book wants me to implement this exercise, I thought maybe with arrays, not sure
So you mean something like this I assume:
Map<char, button> myMap = new HashMap<char, button>();
where button would be an object. As far as the progam goes, how about this pseudocode:

create all the buttons
create labels and text area
add everything to the GUI
get keycodes of all keys used in the virtual keyboard
store the buttons in a map with key codes and the buttons
if user press a key on the actual keyboard
    get its keycode
    find that keycode in the map
    find the button corresponding to that keycode in the map and change the background
if user releases the key on the actual keyboard
    get its keycode
    find that keycode in the map
    find the button corresponding to that keycode in the map and change the background
Violet_82 89 Posting Whiz in Training

Uhm, yes maybe you're right...oops. I didn't occur to me to check somebody else's profile, I automatically assumed that was just for mine.

Violet_82 89 Posting Whiz in Training

I don't think anything was useless, quite the contrary, it is valuable information.
So let's get back to the implementation and the best way forward.
I still need two constructors because I have two types of buttons anyway, a larger one and a smaller one, so I can create two separate JButton objects, unless you think it is better to put everything into one class. I mean I suppose when you say valilla JButton you literally mean a new JButton and nothing else (so no width involved)
Another sticky point is the JButtons creations. You showed me how to do that in the previous post, providing we go for two separate classes that it,

...
row2.add(new KeyButton('q', 'Q'));
row2.add(new KeyButton('w'.,'W'));
...
row4.add(new KeyButton(' ', ' ', 120)); // non-standard width

but I'm thinking, isn't this a little tedious (will have to do this 57+ times for each button), would an array be better or you think the above is a better approach?
thanks

Violet_82 89 Posting Whiz in Training

AH sorry, since the JButtons on the actual keyboard don't generate any event, is it still worth having the KeyButton class implementing ActionListener (it would be now KeyListener though as it's the key in the actual keyboard generating the event) or should I move the event handling into the Keyboard class?
thanks

Violet_82 89 Posting Whiz in Training

Thanks for taking the time to explain it. OK, that's clearer.

OK - I thought the idea was to be able to type on the screen? If it's not going to respond to touches then why use JButtons?

Not sure, that's what the exercise asks, so I'm just following the brief, but I can confirm that there is no functionality attached to the keys in the virtual keyboard, they literally do nothing, they're there only to be highlighted when needed. I guess they want me to use JButtons because it's presumably nice to have buttons that displays characters, I don't know. My understanding of the exercise is that we don't need to worry about shifted characters, in fact if you look at the screenshot you'll notice that numbers are only numbers they don't have the double character. Also about lower case and upper case character, I don't think there is any need for that because for the purpose of touch typing whether it's lower case or upper case it makes no difference (as you press the cap lock button and keep typing) so I don't think I'll include that. What I mean is that, I don't think they want to make it too complicated, considering that I'm not too far ahead in the book.
Good idea with the two constructors though, I can still use it to differentiate between widths.
So, let me code the classes then, and then I'll repost what I produced for feedback.

Violet_82 89 Posting Whiz in Training

Ah OK, that's some different syntax for me, not sure I understand how you envisage that to work, sorry, please bear with me.
Also, I need to clarify a few things about the exercise:
-when you press the buttons on the virtual keyboard, nothing happens, they don't generate any event, the event is generated when you press a key on the physical keyboard; when that happens the button on the GUI changes its background color whih then returns to normal when you release the button.
-the character you press on the physical keyboard will be displayed in the JTextArea;
Here is the actual brief:
"The application should display a virtual keyboard - the attachment I sent at the beginning of the thread - and should allow the user to watch what he is typing on the screen without looking at the actual keyboard. As the uses presses each key the application highlights the corresponding JButton on the GUI and adds the character to the JTextArea that shows what the user has typed so far. When the key is released reset its original background."

Let's see if I understand your code. So KeyButton extend JButton (is there a reason for that?) and implements ActionListener directly, which means that KeyButton will handle all the event handling.
1)You use two chars, but what do they stand for exactly? Maybe normalChar is for a 'normal button' and shiftedChar for a 'bigger one'?
2)You're using an overloaded constructor, …

Violet_82 89 Posting Whiz in Training

HI guys, I'm a bit puzzled about the forum area tags that appear on our profiles, screenshot here
daniweb.png
This is supposed to show you the areas of the forum where you've been posting more, but it's either inaccurate or there is something wrong with the taggin system (the old one was far better I think). It says that I've been posting more in C++ than anything else, which I'm not too sure is the case, in fact I am pretty sure that I posted more in Java than in C++ and more in Javascript than anything else (I can definitely say that Javascript has more posts than PHP), so what's going on? is the tagging system somehow inaccurate (presumably it is as inaccurate as people make it, meaning they can probably add tags that don't really match what's in the post, although in my case I'm not necessarily referring to human error as such, could it be that something has gone wrong when you switched to the new site and the wrong tags have been added to the wrong posts?)
Any idea?

Violet_82 89 Posting Whiz in Training

thanks guys. One more question: the exercise says the buttons should be JButtons, which is great, but what I'm thinking is to perhaps have 2 arrays, one array of JButtons and one of symbols, rather than declaring and creating 57+ JButton variables. But, there is one problem: the sizes of the buttons are not all the same, so if I do this with arrays, how am I going to set different sizes? Like the shift and the space bar, how do I distinguish those buttons from the other ones?
thanks

Violet_82 89 Posting Whiz in Training

Thanks JamesCherril. About that panel with the textArea on it, I thought it might help to keep things into their own panels. So when you say "add it directly", do you mean to add it directly to the JFrame with no intermediate panel?
OK will try to take the same approach when it comes to the handler.
Lastly,

Looking at the first two rows of keys you do not want to try to do that with just a GridBagLayout

so rather than GridBagLayout, do you think that GridLayout is a better idea?

Violet_82 89 Posting Whiz in Training

Hi guys,
I'm now looking at what seems to be a nice exercise on my java book. Basically, the exercise asks me to build a virtual keyboard GUI - see screenshot - and when you press each key on your real keyboard the key you've pressed will change its background on the virtual keyboard and then return back to normal when released. It's an application to learn touch type effectively.
exercise.png
Now, what I'm planning to do is to have two JLabels at the very top, a JTextArea for the text and JButtons for all the keys. I think I'll group every element into a group and let them have their own JPanel, so say, for example, a JPanel for the JLabel and one for the JTextArea. For the keys instead, I could have one JPanel for each row of keys ad then all of them inside one "parent" JPanel.
The JPanel for the JLabels and the one for the JTextArea will have a borderLayout with each element positioned either NORTH or SOUTH. The JPanels wrapper for the keys will have a flowLayout, whereas the JPanel containing each row of keys will instead have a GridLayout instead so I can decide how many cols I need and apply some horizontal margin among each button.
The JFrame itself will have a borderLayout with the JLabel JPanel positioned NORTH, the JPanel containing the JTextArea will be CENTER and the wrapper JPanel for the keys …

Violet_82 89 Posting Whiz in Training

OK, sorry, now that I've done it, I can see the real benefits :-), thanks.
I've also made some changes, added scrollbars when needed (when you increment the font size the textarea grows till it overlaps the buttons, but with the scrollbar this doesn't happen), so here is the final code, with the parametized class added to it and a gridLayout for the JPanel (I've also added a JPanel, why not) and a borderLayout for the JFrame. All compiled and working.
font-size-app_1.png

/*ChangeFont.java*/
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JScrollPane;
public class ChangeFont extends JFrame{
    private JPanel panel;
    private JButton increment;
    private JButton decrement;
    private JTextArea textArea;
    private BorderLayout borderLayout;  
    private GridLayout gridLayout;
    private Font font;
    private int fontQuota;


    public ChangeFont(){//constructor
        super("Change font size application");
        panel = new JPanel();
        gridLayout = new GridLayout(1,2,10,0);//create new gridbag 1 row and 2 cols 
        fontQuota = 9;
        textArea = new JTextArea(5,15);
        increment = new JButton("Increment");
        decrement = new JButton("Decrement");       
        borderLayout = new BorderLayout();
        panel.setLayout(gridLayout);//set layout of panel

        setLayout(borderLayout);//set layout of JFrame      
        panel.add(increment);//add to the JPanel
        panel.add(decrement);//add to the JPanel
        add(new JScrollPane(textArea), BorderLayout.NORTH);//add scrollbar if necessary and add textarea to JFrame directly
        add(panel, BorderLayout.SOUTH);//add JPanel to JFrame
        font = new Font("Serif", Font.PLAIN,fontQuota);//set new font to serif, plain 9px size
        textArea.setFont(font);//set the new font
        //event handling code
        decrement.addActionListener(new FontResizer(-2));
        increment.addActionListener(new FontResizer(2));


    }//end of constructor
    private class FontResizer implements ActionListener{//named class
        int delta;//increment/decrement to be added to fontQuota
        public …
Violet_82 89 Posting Whiz in Training

Sure, I don't mind doing that, but then we remove the anonymous class and replace it with a named one. I'll give it a go

Violet_82 89 Posting Whiz in Training

cool, the "this" keyword often confuse me a little I have to admit. For the purpose of the exercise I left it as it was, as, please do correct me if I'm wrong, I seem to understand that the way I've implemented is correct

Violet_82 89 Posting Whiz in Training

OK I see, thanks for clarifying it

Violet_82 89 Posting Whiz in Training

Well yes I am. Here is the example. I've built this small application as mentioned before, (a text area where users can type and two buttons, (the increase button increases the size of the text and the decrease button decreases it). Since each button hasa different functionality I used 2 anonymous classes,
Here is the ChangeFont.java file

/*ChangeFont.java*/
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
//import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
public class ChangeFont extends JFrame{
    //private JPanel panel;
    private JButton increment;
    private JButton decrement;
    private JTextArea textArea;
    private BorderLayout borderLayout;  
    private Font font;
    private int fontQuota;


    public ChangeFont(){//constructor
        super("Change font size application");
        //panel new JPanel();
        fontQuota = 9;
        textArea = new JTextArea(10,15);
        increment = new JButton("Increment");
        decrement = new JButton("Decrement");       
        borderLayout = new BorderLayout();
        setLayout(borderLayout);
        add(textArea, BorderLayout.CENTER);
        add(increment, BorderLayout.EAST);
        add(decrement, BorderLayout.WEST);
        font = new Font("Serif", Font.PLAIN,fontQuota);//set new font to serif, plain 9px size
        textArea.setFont(font);//set the new font



        //increment event handling
        increment.addActionListener(
            new ActionListener(){
                public void actionPerformed(ActionEvent event){
                    textArea.setFont(new Font("Serif", Font.PLAIN, ++fontQuota));
                }
            }
        );
        //decrement event handling
        decrement.addActionListener(
            new ActionListener(){
                public void actionPerformed(ActionEvent event){
                    textArea.setFont(new Font("Serif", Font.PLAIN, --fontQuota));
                }
            }
        );

    }

}//end of ChangeFont class

And here is how it looks like
font-size-app.png

Violet_82 89 Posting Whiz in Training

thanks, but I'm stuck with java 7 here, company policy I believe. Will stick to AIC for now then.
The lambda expression seems interesting though

Violet_82 89 Posting Whiz in Training

Hi guys,
with event handlings it seems that there are 2 approaches:
1)using an anonymous inner class
2)using a normal inner class.
From what I can see if you have more than one component that is generating an event, say you have 3 buttons, if you go down the route of anonymous inner classes then you need to have effectively 3 inner classes, one for each component. If you instead use a normal - I call it normal, not sure what's the right name for it - inner class then you could techincally use only one.
So, what's better? My understanding is that anonymous inner classes are more widely used because there is less code to write, that's if you use 1, but that might not be the case. What do you guys say? I'm writing a little simple application with three buttons, and I'm thinking not to use an anonymous inner class.
thanks

Violet_82 89 Posting Whiz in Training

cool! Perhaps the choice of layouts might be questionable, but I will slowly get to the gridBagLayout eventually!
thanks

Violet_82 89 Posting Whiz in Training

Oh, well, in that case I misread it, sorry. I would have thought that (function($) {})(jQuery); was equivalent to document.ready(function(){}).
The thing is, I have this situation:

document.ready(function(){
//my code
});
function function1(){
//my code
}
function function2(){
//my code
}
function function3(){
//my code
}
...

Does it mean that everything (document ready and functions) can sit inside (function($) {})(jQuery);?

Violet_82 89 Posting Whiz in Training

Let's see if I got it right...here is the version with JPanel instead, and I've used two layout managers, a BorderLayout (which I used to place the JPanel at the bottom of the JFrame) and a GridLayout to place the buttons inside the JPanel.
It seems to work, here is a screenshot:
with_jpanel.png

/*CreateFrame.java*/
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
public class CreateFrame extends JFrame{
    //create new JPanel
    private JPanel panel;
    private JButton button1;
    private JButton button2;
    private JButton button3;
    private GridLayout gLayout;
    private BorderLayout bLayout;

    public CreateFrame(){
        super("border layout buttons");//cal super class constructor
        panel = new JPanel();//create new JPanel
        bLayout = new BorderLayout();
        gLayout = new GridLayout(1,3);//create new gridbag 1 row and three cols     
        panel.setLayout(gLayout);//set layout of JPanel to gridbag  

        button1 = new JButton("Button1");
        panel.add(button1);//add button to JPanel
        button2 = new JButton("Button2");
        panel.add(button2);//add button to JPanel
        button3 = new JButton("Button3");       
        panel.add(button3);//add button to JPanel   
        setLayout(bLayout);
        add(panel, BorderLayout.SOUTH);//adding the JPanel at the bottom of the JFrame      
    }
}//end of CreateFrame



/*CreateFrameTest.java*/
import javax.swing.JFrame;
public class CreateFrameTest{
    public static void main(String[] args){
        CreateFrame createFrame = new CreateFrame();
        createFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        createFrame.setSize( 300, 200);
        createFrame.setVisible( true );
    }
}//end of CreateFrameTest
Violet_82 89 Posting Whiz in Training

Thanks. Maybe it's better if we look at some code.
Here is the application (2 files) with no JPanel:

/*CreateFrame.java*/
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
public class CreateFrame extends JFrame{
    //create and instantiating new JPanel
    //private JPanel panel = new JPanel();
    private JButton button1;
    private JButton button2;
    private JButton button3;
    private BorderLayout layout;

    public CreateFrame(){
        super("border layout buttons");
        layout = new BorderLayout(5,5);
        setLayout(layout);

        //panel = new JPanel();
        button1 = new JButton("Button1");
        add(button1, BorderLayout.NORTH);
        button2 = new JButton("Button2");
        add(button2, BorderLayout.SOUTH);
        button3 = new JButton("Button3");
        add(button3, BorderLayout.CENTER);      
    }
}//end of CreateFrame    


    /*CreateFrameTest.java*/
import javax.swing.JFrame;
public class CreateFrameTest{
    public static void main(String[] args){
        CreateFrame createFrame = new CreateFrame();
        createFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        createFrame.setSize( 300, 200);
        createFrame.setVisible( true );
    }
}//end of CreateFrameTest

I'm extending JFrame only because that's the way the book is telling me to do it. I suspect that it's preparing me for when extending that class is necessary (presumably the author will be later overriding or extending some functionality of the JFrame class, not sure).
So, let's say now that I want to add those three buttons in a row at the bottom of the window as you said, I'll rewrite this application with a JPanel in. I have a question thought: do I have to add the components to the JPanel the same way I add them to the JFrame (method add()), then give the JPanel a layout, then add the JPanel to the JFrame and add a layout to the JFrame too? Is …

Violet_82 89 Posting Whiz in Training

thanks, but the problem was for functions outside document.ready, that's what I meant

Violet_82 89 Posting Whiz in Training

HI guys,
as I'm gettng into Java GUI again after a long time, I'm trying hard to remember things, but not everything is that clear anymore.
I'm in the process of building a very simple GUI application with a few buttons.
First question is about the JFrame and JPanel. From what I remember - and what I found online - the JFrame is at the top level of the hierarchy, but do I need to have a JPanel in my application or can I put my GUI components directly onto the JFrame (providing my class extends the JFrame of course)? It's a little comfusing for me because I've seen code with a JPanels and GUI components on them but I've also seen JFrames with GUI components on them and I'm not sure why we can do both or when we should do one or the other.
thanks

Violet_82 89 Posting Whiz in Training

Sorry, bit late to the party!
There are many different ways you can achieve this. gentlemedia's suggestion is one way to do it.
Techically, you could still use fix width for your image, providing that, with media queries, you change the width accordingly, depending on which device you're targeting. For example, say that on desktop your image is 500px wide, then when you go to tablet reduce it to, say, 250px and then to 150px on mobile (that depends on how important your image is I suppose).
Or, it is pretty normal to remove the floats from divs when in mobile device and stack your containers on the top of each other (in your case image and box with text).
The media queries I often use are these:

/*Tablets*/ @media (min-width:768px) and (max-width:1023px){...}
/*Mobiles*/@media (max-width:767px){...}

Hope this helps

Violet_82 89 Posting Whiz in Training

Cool, I understand, thanks a lot for the explanation!

Violet_82 89 Posting Whiz in Training

Thanks guys, maybe I begin to remember : -). Just one last thing then: all this is because the test class is attempting to print an object, but, say that I instead replace System.out.println(patient); with something like

System.out.println("name: " + patient.getName() + " surname: " + patient.getSurname() + " date: " + birth.getDay() + "/" + birth.getMonth() + "/" + birth.getYear() );

where I don't use objects, then I can remove all my toString()methods and replace them with normal System.out.println.... Is that correct?
thanks

Violet_82 89 Posting Whiz in Training

I thought toString() was only called if you attempt to print an object, like if you do something like System.out.println(patient);. I think I'm getting confused because I used return String.format() rather than something like return "Date is %d-%d-%d\n",getDay(),getMonth(),getYear(). what's the difference between these two then?

public String toString(){
        return String.format(
            "Date is %d-%d-%d\n",getDay(),getMonth(),getYear()
        );
     }


public String toString(){
        return  "Date is %d-%d-%d\n",getDay(),getMonth(),getYear();
     }

Also, please bear with me as I haven't done Java for quite a long time. Let's quickly look at this scenario: Say that in my Date class I remove the toString() method completely. When I run the app and create a Date object, the date information prints OK because in Date.java I have this

System.out.printf(
            "Date is %d-%d-%d\n",getDay(),getMonth(),getYear()
        );

then, control returns to PatientTest.java. I then create a patient object and then control returns back again to PatientTest: here this statement System.out.println(patient);calls the toString() methods of patient first and then attempts to call the toString of Date, which I have removed, hence I get the "rubbish" data. Is that a fairly accurate representation?
thanks

Violet_82 89 Posting Whiz in Training

Hello guys, long time no see!
i've put together a very small simple console base application that takes a date and a few strings and print them off.
Let's look at the code first.
Date.java

/*Date.java
this class represents dates
*/
public class Date{
    private int month;
    private int day;
    private int year;

    //constructor
    public Date(int dayDate, int monthDate, int yearDate){
        day = checkDay(dayDate);
        month = checkMonth(monthDate);
        year = yearDate;//no validation
        System.out.printf(
            "Date is %d-%d-%d\n",getDay(),getMonth(),getYear()
        );

    }

    public int getDay(){//getter
        return day;
    }
    public int getMonth(){
        return month;
    }

    public int getYear(){
        return year;
    }

    private int checkDay(int testDay){//test day
        if((testDay <= 31) || (testDay > 0)){//if between 1 and 31 it's ok
            return testDay;
        }
        else{//if not
            throw new IllegalArgumentException("day must be between 1 and 31");//throw exception
        }
    }

     private int checkMonth(int testMonth){
        if((testMonth <= 12) || testMonth > 0){
            return testMonth;
        }
        else{
            throw new IllegalArgumentException("month must be between 1 and 12");//throw exception
        }
     }

     public String toString(){
        return String.format(
            "Date is %d-%d-%d\n",getDay(),getMonth(),getYear()
        );
     }

}//end of Date

then Patient.java

/*Patient.java
this class represents a patient
*/
public class Patient{
    private String name;
    private String surname;
    private Date dateOfBirth;

    public Patient(String theName, String theSurname, Date birthday){
        name = theName;
        surname = theSurname;
        dateOfBirth = birthday;     
    }
    public String getName(){
        return name;
    }

    public String getSurname(){
        return surname;
    }

    /* public String getBirth(){
        return dateOfBirth;
    } */
    public String toString(){
        return String.format("Name: %s, Surname: %s, Date of birth: %s ",
            getName(), getSurname(), dateOfBirth
        );
    } …
Violet_82 89 Posting Whiz in Training

HI guys, I've just run into an issue. Basically I'm working t a wordpress site, and there are some conflicts with the usage of the "$" sign so I used this in the document ready to allow me to use "$" in place of jQuery:

jQuery(document).ready(function($){ 
    ...
});

It works very well inside the document ready but in my script I have plenty of functions using the "$" and I'd like to be able to use that rather than go through it and replace all $ with jQuery, for example take one of the functions I have outside document ready:

function getNavigationStatus(){//whether navigation is open or closed
    var isNav;
    if($(".navigation").hasClass("open")){
        isNav = true;
    }
    else{
        isNav = false;
    }
    return isNav;
}

I need to be able to use $ rather than jQuery. Any idea (other than replacing every single $ of course)?
thanks

Violet_82 89 Posting Whiz in Training

thanks rubberman. Sorry I think I misread your answer. Checking the actual devices now, the cd/dvd burner has this on the stick at the back: 12V----2.5A. The HD docking station, whose adapter I'm using for my cd/dvd burner has this on the stick instead: input:100-240V,50/60Hz,1.5A, so still 1A difference

Violet_82 89 Posting Whiz in Training

thanks rubberman. OK, just by looking at those screenshots, the original charger, the one that doesn't work, provide a DC output of 12v ----- 2A, whereas the one I'm planning to use provides output of 12V ----- 3000mA, so if I understand this correctly there is 1A difference. Is it a bad thing?
thanks

Violet_82 89 Posting Whiz in Training

thanks rubberman.

Assuming that the new power supply provides at least the same current rating and voltage of the old one

Presumably by that you mean that both, the old and the new one, provides 12V. If that's what you mean, then yes, as per the screenshots I uploaded, both chargers provide 12V

Violet_82 89 Posting Whiz in Training

I think the problem might be due to the fact that when you scroll up in chrome in android, the address bar disappears and when you scroll down it appears again.

Violet_82 89 Posting Whiz in Training

Uh, I'm really sorry diafol (what's your monthly allowance?!), not sure if you checked before or after I changed the images. The site is now 6MB, pretty good compared to the over 16MB I had before. Of course still heavy for 3G, but the images need to be big. If you manage to get your android device on the wireless please have a look :-)
thanks anyway

Violet_82 89 Posting Whiz in Training

Hello guys, I wonder if you can help me with this. Basically I have a LG cd/dvd burner (specs here http://s13.postimg.org/rt0fl9jpz/IMG_20150918_171817.jpg) which of course came with the 12v original adapter ( specs here http://s8.postimg.org/uj5ejvo85/IMG_20150918_171833.jpg) . Some time ago, the CD/DVD burner stopped working. I've always thought it was the adapter but I didn't have another 12V one to try. I managed to get hold of one today, it belongs to a HD docking station, and I thought I'd give it a try (specs of this adapter here http://s27.postimg.org/qoy46bx8j/IMG_20150918_171856.jpg). So I plugged it in, thinking, well the worst it can happen is that it fries my DVD burner, but in fact it worked, and I managed to open it, remove an old CD from it and close it again, I didn't burn any CD or DVD. My question is, is it safe to use this new adapter with the CD/DVD burner? They are both 12V so it should be fine shouldn't it? Does anyone with a bit more knowledge in the matter know?
thanks

Violet_82 89 Posting Whiz in Training

Right, so I've done a few things:
1)as said I changed the png into jps, and, well, that did help as the size of the website has gone down as well as the download time.
2) done some readings, and found an interesting article, http://gomakethings.com/javascript-resize-performance/. I thought I'd give this throttling a go, so I've implemented the solution described there, which, in brief, puts a timer in place inside the resize()function and calls another function that does what you want to happen on resize every XX as opposed to let the $(window).resize() do its work. Alas, this hasn't made any difference whatsoever, in chrome android (it's android 5 by the way) I still get this page snapping when I change the direction of the manual scrolling. You can see the two versions here:
-without timer: http://antonioborrillo.co.uk/agency_test/home.html
-with timer: http://antonioborrillo.co.uk/agency_test/test/home.html

If we want to delve into the code, then, let's have a look. Here is the portion of the js with the timer:

$(document).ready(function(){   
    var is_open;//navigation status, open or closed
    var resizeTimer; // Set resizeTimer to empty so it resets on page load
    ...
    function resizeFunction() {
        console.log("resize called");
       // Stuff that should happen on resize
        setHeight($(".pseudoPage"));//set height of pseudo pages on resize
        /* $('html, body').animate({//scroll back up to the top
            scrollTop:0
        },100); */  
        resizeCarousel();
    };
    $(window).resize(function(){//when window resize
        clearTimeout(resizeTimer);
        resizeTimer = setTimeout(resizeFunction, 250);

        //setHeight($(".carouselImages .imageWrapper ul img"));

    });


function setHeight(toSet){//recalculate and set height of pseudo pages
    var browserHeight = …
Violet_82 89 Posting Whiz in Training

Hi diafol,
so I cleared my cache and checked the values, as I did expect them to be quite high (time of page load and size) because I have really big images there - see screenshot here http://s14.postimg.org/h7g3pd969/net_Panel.jpg - but I've never really had any crash as such, the first time I load the site I do see the images populating the container though, but I knew that already and I thought, well will leave with that. I mean it would be nice to sort this out as well, but the images need to be big unfortunately. Saying that, I've just noticed they are .PNGs, so I'll save them as .JPGs, that's will help to bring down the size and the download time I'm sure. More important than that, is that business of the page snapping into some position that seems to be happening only on android, in chrome specifically, (I checked on the iphone and it is all OK), and I can only think of one cause really, that $(window).resize() that runs everytime the page is resized, and in android is seems to run also when the page isn't resized, so I was wondering if there is a bug in android or that's the way it is supposed to work. If you manage to check on android please let me know.

Violet_82 89 Posting Whiz in Training

HI, I've just run into something peculiar. Let me explain the functionality of the site I'm working on first http://antonioborrillo.co.uk/agency_test/home.html . Every time the site gets resized - if you resize the browser window or if you change orientation on the device you 're using - I recalculate the height of the 4 sections or pseudo-pages (it's a 1 page website). SO obviously I'm using resize(). Now, it all works OK, except for mobile browser (well, at least this is where I spotted the issue and I'm testing on chrome in Android): if I scroll in one direction, say down and then up, that's when a problem occurs: the page snaps, as if it's repositioning itself, it doesn't snap hundreds of pixels, but enough to be quite noticeable. Can somebody test this as well on chrome android and let me know if they get this issue? Does anybody know why that happens?
thanks

Violet_82 89 Posting Whiz in Training

OK, after going through the code over and over again, I found the solution. Basically I had to have a "transitional" z-index of 2, and it all works.

Violet_82 89 Posting Whiz in Training

OK, done some work, got rid of a lot of unnecessary code and changed the image when the controller is clicked on - the only thing is that I got rid of the animation in the manual carousel, here is the function that does it all:

(document).ready(function(){
    //console.log("ohi");
    init();//initialize carousel
    resizeCarousel();
    var timer = setInterval('startCarousel()', 3000);
    $(".controllers a.indicator").click(function(){//when a controller is clicked
        $(".imageWrapper div").css("z-index",1);//index of all div to 1
        clearInterval(timer);//stop the carousel
        $(".controllers a.indicator.active").removeClass("active");//remove active from all of controllers

        /* $(".imageWrapper div.active").fadeOut(1550,function(){//fade out first image
            $(this).show().removeClass("active");//reset z-index, reverse the fadeOut with next     
            $nextSlide.css("z-index",3).addClass("active");//move image to the top
            updateController();//update the controller
        }); */


        $(".imageWrapper div.active").removeClass("active").css("z-index",2);//remove active from the div
        $(this).addClass("active");

        $("a.indicator").each(function(index){//go thru each controller
            var $this = $(this);

            if($this.hasClass("active")){//if it has active class               
                //updateCarousel(index);
                $(".imageWrapper > div").eq(index).addClass("active").css("z-index",3);//get the equivalent controller and give it an active class
            }
        });

    });

As you can see the fadeing out is commented out, because I just can't get it to work. This is what the new code does:

click on controller
    stop the carousel etc
    drop  index of all divs (slides) to 1
    remove active class from currently active controller
    remove active class from currently active slide and drop its index to 2
    add active class to clicked controller
    run thru all controllers
        find the active one and assign active class to the corresponding slide and increase its z-index to 3

I'm not sure how the fadingOut will fit in here

Violet_82 89 Posting Whiz in Training

Hi all, I wonder if you can help me at all, as I run into an annoying problem. I created an automated crossfade but when I click on the controller I want it to change into a manual one, but unfortunately the manual one doesn't work as expected. You can see it in action here: http://antobbo.webspace.virginmedia.com/future/home.html If you let it run, it will work but if you try to use the manual controllers you'll see that eventually the crossfade is not smooth and it doesn't crossfade properly. The problem, I believe is a z-index, as in the images don't get the right z-index at the right time.
Let's look at the code. Here are he relevant bits:
HTML:
<div class="pseudoPage home">

    <div class="carouselImages">
        <div class="imageWrapper">                       
            <div class="slide active">
                <img src="images/hugeImage1.png" alt="">
                    <div class="message">
                        <div class="msgWrap">
                            <div class="title">
                                <span>Lorem ipsum</span>
                            </div>
                            <div class="text">
                                <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit.</span>
                            </div>
                        </div>
                    </div>
            </div>
            <div class="slide">
                <img src="images/hugeImage2.png" alt="">
                <div class="message">
                    <div class="msgWrap">
                        <div class="title">
                            <span>Interactive</span>
                        </div>
                        <div class="text">
                            <span>We all love interactive sites</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="slide">
                <img src="images/hugeImage3.png" alt="">
                <div class="message">
                    <div class="msgWrap">
                        <div class="title">
                            <span>Crossbrowser</span>
                        </div>
                        <div class="text">
                            <span>All our websites are tested across all major browsers</span>
                        </div>
                    </div>
                </div>
            </div>                           
        </div>                   
        <div class="controllers">

        </div>
    </div>
</div>

The controllers are added dynamically, depending on how many images you …

Violet_82 89 Posting Whiz in Training

Sounds like a good idea. 2 questions though:
1) in the class Transaction, shouldn't public Item Item { get; set; } and public Category Category { get; set; } be virtual?
2)Are Item and Category classes in a many-to-may relationship?
thanks

Violet_82 89 Posting Whiz in Training

well, I'm not necessarily screaming at them for not giving me things for free, I'm screaming at them for not helping me, which may or may not result in them giving me a free key. Fact is, they couldn't do anything to help. Of course, lesson learned, I will make a note of the windows keys from now on (starting from my main computer) but my point is, I'm not surprised if people resort to piracy to get software if software companies don't have any way to help people if they need help. I don't care if they can't determine whether I'm lying or not, if somebody needs help and they can't give any, people will go elsewhere, it is pretty obvious.

Violet_82 89 Posting Whiz in Training

Fair enough pcbugfixer, I didn't know you were a reseller, apologies if I sounded a bit funny, it's just that when people asks for those details I think it is legitimate to feel a bit suspicious.
Let me also clarified a few points also. Samsung misunderstood the issue to an extent, I didn't replace the HD, I just formatted it, and I couldn't use any script because the formatting process had already started unfortunately (yes my fault but I was absolutely sure I had the windows key).
Why post here? Because, as said, I realized too late that I had no windows key.
The reason why I formatted it, was because I had in mind to sell the laptop, and since it came with windows xp, I wanted to put it back. But like I said, I managed to fix the screen issue which prompted me to decide to sell it in the first place, so eventually decided to keep it. Yes windows 7 is a good idea, but I don't want to buy it to be honest, that's why I put ubuntu on it.

Violet_82 89 Posting Whiz in Training

thanks guys. I talked to samsung, here is the reply in full:

Dear Mr. XXX, 
Thank you for your email. Your customer reference number is 2118571455. 
This is to acknowledge that we have received your email about the product key. As I am trying to contact you on the phone number provided (xxxxxx), unfortunately I was not able to reach you.

In regards to your email, Samsung do not provide an installer or driver to all Samsung laptops and PCs, due to the software and drivers are pre-installed to the original Hard Disc Drive of your laptop. As you have mentioned that you have change your Hard Disc Drive (HDD), unfortunately, there is no possible way we can recover the product of the pre-installed windows. What we usually advise to our customers is to buy a new installer or driver to the Authorised Dealers of Microsoft. Or you may contact Microsoft (details below), for the purchased.

Microsoft UK Headquarters
Microsoft Campus
Thames Valley Park
Reading 
RG6 1WG 
Telephone: 0344 800 2400

For you able to check on the product key, you may follow the guidelines below. However, please be reminded the product key works only to the pre-installed software. 
1. Copy and paste the following into a Notepad window:
Set WshShell = CreateObject('WScript.Shell')
MsgBox ConvertToKey(WshShell.RegRead('HKLM\SOFTWARE\Microsoft\Windows 
NT\CurrentVersion\DigitalProductId')) 
Set WshShell = CreateObject("WScript.Shell")
MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = …