Violet_82 89 Posting Whiz in Training

OK cool thanks. Other than relying on the IDE, is there a list detailing what tags need a closing tag and which ones don't? A bit like the HTML doc type

Violet_82 89 Posting Whiz in Training

hi guys, I have a dell xps 17 and I am thinking to purchase an extra Hard Drive - as I have an extra slot available. Ideally I don't want less than 1TB, maybe even more (probably not solid state as they are still too expensive) so I was wondering:
-how do I know if there is a limit to the capacity of the HD? In that can I buy up to 1.5TB for the sake of argument?
-How is it going to work when I boot up? On the current HD I have installed Ubuntu and Windowd 7 and at boot time I can choose which OS to run. On the new HD I am planning to install Ubuntu again but with a virtual copy of windows 7 and if everything goes well, I will probably remove Ubuntu from the first one, resize it and leave the proper copy of WIndows 7
any idea?
thanks

Violet_82 89 Posting Whiz in Training

Thanks JorgeM, yes the p tag business looked wrong to me too, but being really new to ASP.NET and visual I thought I'd ask. So with regard to opening and closing tags in controls, presumably the IDE is clever enough to determine which one needs a closing tag and which not?

Violet_82 89 Posting Whiz in Training

Hello all, I am very very new to ASP.NET - just started looking into it a few days ago - and I got a book out to get the basics of APS.NET, Visual studio (which I haven't installed as yet) and C# (the book is ASP.NET 3.5 a beginners guide by William B Sanders). As I flicked through the first examples of code, I have noticed something and I am not sure whether it's me being silly, a mistake, or how things are. Let's have a look at a few of these examples.
1)this aspx file is part of a larger example to demonstrate variable types (which in this case, it is not my concern by the way):

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConVar.aspx.cs"
Inherits="ConVar" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Constants and Variables</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Label ID="YourAge" runat="server" Text="19" />
            </div>
        </form>
    </body>
</html>

So, the asp tag seems to auto close but I swear I'd seen somewhere else that it has to be matched by an equivalent closing tag like </asp:Label>. Can anybody shed some light on this for me please?

2)Second one is far more interesting. Again it is part of a larger example to demonstrate basic comparison:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SimpleIf.aspx.cs"
Inherits="SimpleIf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Simple Conditional</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" …
Violet_82 89 Posting Whiz in Training

Hi all, I have come across something weird today. In my HTMl page I have an iframe pulling content from somewhere else. The height and the width of the iframe as set in the CSS. In the head tag of the Iframe there are 2 CSS files, one for desktop and tablets and one for mobile as below:

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="css/iframeStyles.css" />
    <link rel="stylesheet" type="text/css" href="css/iframeStyles-mobile.css" />
</head>

Now, for some reason that I cannot grasp, only the second CSS takes effect with the result that the iframe and its content have a mobile layout, even in desktp and tablets. What's effectively happening in here is that the mobile rules set in the mobile CSS file are overriding those set in the iframeStyles.css. How is that possible? By the way, the styles in the mobile css are set correctly, all wrapped inside a

@media (max-width:767px){
...
}

Does anybody have any idea why that's happening and how to get around that? I had looked online of course but I could 't find anything particularly useful
thanks

Violet_82 89 Posting Whiz in Training

Ah, thanks DJBirdi, that's actually really clear, thanks!

Violet_82 89 Posting Whiz in Training

Ah I see, thanks!

Violet_82 89 Posting Whiz in Training

hi guys, I am doing some tests on e.currentTarget vs $(this) to get things clear in my head. It is said that the two are equivalent, so I created a test page with the following code in (among the other things of course):

<div class="testLink">
    <a href="#">Link</a>
</div>

The script goes:

    /*TESTS ON THE TESTLINK*/
    $(".testLink").click(function(e){
        e.preventDefault();
        console.log("e.currentTarget is " + e.currentTarget);
        console.log("this is " + $(this).html());
    });

    /*EN OF TESTS ON THE TESTLINK*/

And this is the result I get:

e.currentTarget is [object HTMLDivElement]
this is <a href="#">Link</a>

Now, first of all I would like to ask, how do I actually print the value of e.currentTarget to obtain an HTML tag as I did for $(this).html())?
Second - but perhaps more importantly - to me the results do not coincide: e.currentTarget seems to be returning the DIV containing the link and $(this) returns instead the expected result. Can anybody clarify please?
thanks

Violet_82 89 Posting Whiz in Training

Righ, here is what I came up with.
First the most annoying prob, I can't get it to layout properly. I want the txt field on the top and the buttons at the bottom. I purposely used the easiest layout manager because I didn't want to worry about the layout, and yet, here I am, with a broken layout. I know it can be done with that because the textbook has done a similar program with a text field at the top and 2 radio buttons aligned centrally at the bottom with the flowlayout.
Second the jtextfield doesn't grow with the text. At first, I did a very stupid thing, textField.pack(), then I realized that pack needs to be called on a JFrame object, but I don't have any so I called it from the other file, textSizeTest.java, but, almost as I expected it, it doesn't work. I know we said I need to call it everytime the button is pressed, but how do I do it?
SHould I create a JFrame object in the main file and call pack() on it? Any input welcome as usual
Here are the files:

/*TextSize.java*/
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JTextField;

public class TextSize extends JFrame{
    private JTextField textField;//where the txt sits
    private JButton increaseSize;//plus button
    private JButton decreaseSize; //minus button
    /* private Font biggerFont;//bigger font object
    private Font smallerFont;//smaller font object */
    private Font newFontSize;
    private int size;//font size …
Violet_82 89 Posting Whiz in Training

Will try! thanks!

Violet_82 89 Posting Whiz in Training

Right, so does it mean that everytime I press the + or - button I have to call pack()?

Violet_82 89 Posting Whiz in Training

hi all, I wanted to build a small and easy interface where I have some text and two buttons, one to increase the size of the text and one to decrease it. I haven't built anything as yet, I am still thinking what's the best way to go.
In terms of where the text sits, I thought that perhaps a normal JTextField is probably not a good idea because it will have to grow/shrink with the text and I am not sure that a JTextField has the ability to do that. SHould I use a text area instead? Or what do you guys suggest?

Violet_82 89 Posting Whiz in Training

right, thanks guys, sorry, I just finding it incredibly difficult to find my way around the API.

Violet_82 89 Posting Whiz in Training

ahm, sorry to resurrect an old thread, but it is relevant to what I am doing now. I want to find out what events a JButton supports. I am on the API page and hell, where do I find the type of events supported?! I know there is a tutorial here and I am looking at that too http://docs.oracle.com/javase/tutorial/uiswing/events/eventsandcomponents.html#all but if it wasn't for the table in the tutorial telling me which event is supported, I would be completely lost

Violet_82 89 Posting Whiz in Training

Hold on, sorry just noticed, shouldn't I use event if(event.getStateChange() == event.SELECTED ){ rather than ItemEvent if(event.getStateChange() == ItemEvent.SELECTED ){?

Violet_82 89 Posting Whiz in Training

OK cool, I tried with the above test and it seems OK :-), thanks for bringing the issue up! New code is here:
http://pastebin.com/E0T3BXi4
ActionEvent solution...you will most often see in ordinary use.
I guess the author then used it just to demonstrate the ItemEvent

Violet_82 89 Posting Whiz in Training

um, so something like this essentially (first solution)

public void itemStateChanged( ItemEvent event ){
            if(event.getStateChange() == ItemEvent.SELECTED ){
                getContentPane().setBackground( colour );
            }
        }//end of method
Violet_82 89 Posting Whiz in Training

Hi thanks for your feedback. I had no idea the issue existed, the textbook hasn't mentioned it - maybe it will at some point.

1) check the event to make sure its the right one or

how would I check the event? Is it just a matter of identifying which one is selected with perhaps isSelected()

2) use an action listener

Is it just a matter of replacing ItemListener with actionListener, so implementing the itemListener interface and passing the itemEvent?

Violet_82 89 Posting Whiz in Training

That's what I thought. I used Chrome

Violet_82 89 Posting Whiz in Training

hi guys, I posted something similar a long time ago, but I had the same issue againt today. I wanted to upload some files onto the forum (a small java program ) but I couldn't do it. Now, I know that .java files are not allowed to I saved them as .txt but I still got the error message saying that the file type is not allowed. I am pretty sure that text files were allowed, or am I wrong?
thanks

Violet_82 89 Posting Whiz in Training

OK, got that to work in the end, here is the source code in case - I doubt it :-) - any newbie like me wants to play around with it:

/*ColorChange.java*/
import java.awt.FlowLayout;
import java.awt.Color;
import javax.swing.JFrame;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;

public class ColorChange extends JFrame{
    //declare button variables
    private JRadioButton redButton;
    private JRadioButton blueButton;
    private JRadioButton greenButton;
    private JRadioButton magentaButton;
    private ButtonGroup radioGroup; 
//use example of font
    public ColorChange(){   
        super("colours test");
        setLayout( new FlowLayout());//set layout
        //radio buttons
        redButton = new JRadioButton( "Red", true );
        blueButton = new JRadioButton( "Blue", false );
        greenButton = new JRadioButton( "Green", false );
        magentaButton = new JRadioButton( "Magenta", false );
        //add to JFrame
        add( redButton );
        add( blueButton );
        add( greenButton );
        add( magentaButton );
        //add to the buttongroup
        radioGroup = new ButtonGroup();
        radioGroup.add( redButton );
        radioGroup.add( blueButton );
        radioGroup.add( greenButton );
        radioGroup.add( magentaButton );
        //register events
        redButton.addItemListener(new RadioButtonHandler(Color.RED));
        blueButton.addItemListener(new RadioButtonHandler(Color.BLUE));
        greenButton.addItemListener(new RadioButtonHandler(Color.GREEN));
        magentaButton.addItemListener(new RadioButtonHandler(Color.MAGENTA));
        //set the initial red colour
        getContentPane().setBackground( Color.RED );
    }//end of constructor

    //handling events
    private class RadioButtonHandler implements ItemListener{
        private Color colour;

        public RadioButtonHandler( Color targetColour){//constructor taking a color object
            colour = targetColour;
        }//end of constructor

        public void itemStateChanged( ItemEvent event ){
            getContentPane().setBackground( colour );
        }//end of method

    }//end of inner class

}//end of class



/*ColorChangeTest.java*/
import javax.swing.JFrame;
import java.awt.Dimension;
public class ColorChangeTest{
    public static void main( String[] args ){
        ColorChange colorChange = new ColorChange();
        colorChange.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        colorChange.setVisible( true );
        Dimension minimumSize = new Dimension( 400, 200 );
        colorChange.setMinimumSize( minimumSize );
        colorChange.pack();
    }//end …
Violet_82 89 Posting Whiz in Training

I found that the bootstrap media queries used in the grid - please note I am not saying you have to use the bootstrap grid, just the media queries - are pretty good, I have used them in the past a few times http://getbootstrap.com/2.3.2/scaffolding.html#responsive or you can have a look here http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
Unfortunately you can't possibly expect to get a perfect site for all the possible devices, because there are always new coming out, so all you can do is to try to suit most of them

Violet_82 89 Posting Whiz in Training

thanks, I knew you would have mentioned java 8 lol! I will give a go to the first solution, and post back :-), I am sure I will get stuck again.
Funny though, I thought that in java 7 anonymous classes were heavily used, so I am surprised to hear that an inner class can't be easily implemented for such an easy taks!

Violet_82 89 Posting Whiz in Training

Hi guys, I run into a problem. I am trying to write a small program. There should be 4 radio buttons and each of them controls the colour of the Content Pane.
The problem I have is with the anonymous inner class (I hear JamesCherrill muttering "why do you bother?", but hey!) and essentially I don't know how to attach the handlers - because I need to have multiple
radio buttons. If I didn't use the anonymous class I would do this:

redButton.addItemListener(new RadioButtonHandler(Color.RED));
blueButton.addItemListener(new RadioButtonHandler(Color.BLUE));
greenButton.addItemListener(new RadioButtonHandler(Color.GREEN));
magentaButton.addItemListener(new RadioButtonHandler(Color.MAGENTA));

but how do I do that with an anonymous class?
Is this allowed:

redButton.addItemListener(
    new ItemListener(
        ...
    )
)

blueButton.addItemListener(
    new ItemListener(
        ...
    )
)
greenButton.addItemListener(
    new ItemListener(
        ...
    )
)

magentaButton.addItemListener(
    new ItemListener(
        ...
    )
)

I am not sure if I can do that, so for now I only have a basic version if you like:

/*ColorChange.java*/
import java.awt.FlowLayout;
import java.awt.Color;
import javax.swing.JFrame;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;

public class ColorChange extends JFrame{
    private JRadioButton redButton;
    private JRadioButton blueButton;
    private JRadioButton greenButton;
    private JRadioButton magentaButton;
    private ButtonGroup radioGroup; 
//use example of font
    public ColorChange(){   
        super("colours test");
        setlayout( new FlowLayout());
        //radio buttons
        redButton = new JRadioButton( "Red", true );
        blueButton = new JRadioButton( "Blue", false );
        greenButton = new JRadioButton( "Green", false );
        magentaButton = new JRadioButton( "Magenta", false );
        add( redButton );
        add( blueButton );
        add( greenButton );
        add( magentaButton );

        radioGroup = new ButtonGroup();
        radioGroup.add( redButton …
Violet_82 89 Posting Whiz in Training

Thank you, sorry it didn't occur to me to check on the API!

Violet_82 89 Posting Whiz in Training

HI guys,
I wonder if you can help me understanding this please. Take the following code:

// Fig. 14.23: ListFrame.java
// JList that displays a list of colors.
import java.awt.FlowLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.ListSelectionModel;

public class ListFrame extends JFrame 
{
   private JList colorJList; // list to display colors
   private static final String[] colorNames = { "Black", "Blue", "Cyan",
      "Dark Gray", "Gray", "Green", "Light Gray", "Magenta",
      "Orange", "Pink", "Red", "White", "Yellow" };
   private static final Color[] colors = { Color.BLACK, Color.BLUE,
      Color.CYAN, Color.DARK_GRAY, Color.GRAY, Color.GREEN, 
      Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK, 
      Color.RED, Color.WHITE, Color.YELLOW };

   // ListFrame constructor add JScrollPane containing JList to JFrame
   public ListFrame()
   {
      super( "List Test" );
      setLayout( new FlowLayout() ); // set frame layout

      colorJList = new JList( colorNames ); // create with colorNames
      colorJList.setVisibleRowCount( 5 ); // display five rows at once

      // do not allow multiple selections
      colorJList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );

      // add a JScrollPane containing JList to frame
      add( new JScrollPane( colorJList ) );

      colorJList.addListSelectionListener(
         new ListSelectionListener() // anonymous inner class
         {   
            // handle list selection events
            public void valueChanged( ListSelectionEvent event )
            {
               getContentPane().setBackground( 
                  colors[ colorJList.getSelectedIndex() ] );
            } // end method valueChanged
         } // end anonymous inner class
      ); // end call to addListSelectionListener
   } // end ListFrame constructor
} // end class ListFrame

This line colorJList = new JList( colorNames ); creates a new objects and passes a parameter - an array - to the constructur. But where is the …

Violet_82 89 Posting Whiz in Training

uhm, well I can't argue with that...as I am going through anonymous classes right now...

Violet_82 89 Posting Whiz in Training

Thanks guys.
@JamesCherrill, thanks for the links I had seen at least one of those already :-). You mentioned Java 8 in another post already, but I think that for now I will stick to 7, I'd like to learn more (if I ever will) before upgrading and diving into a slightly different syntax

Violet_82 89 Posting Whiz in Training

Hi all, I started to look into event handlers, and there is something I would like to ask, sorry if this is a silly one. I can see that different Java components generate different events when the user interacts with them, but when it comes down to 1)which interface the class that represents the event handler implements (ActionListener,ItemListener etc) and 2) what type of event is generated (ActionEvent, ItemEvent etc), how do I know which one to use? I mean, so far I know that if I want to implement event handling for, say, a textField, the inner class (or anonymous one which I haven't looked into as yet) implements the ActionListener interface and that the event passed on to the class method is and ActionEvent. But how do I know what each java component does? "API" I hear you saying, and well, "To an extent" I'd reply. If I have a look in the API for textField I have a list as long as my arm of methods, classes, etc etc http://docs.oracle.com/javase/7/docs/api/java/awt/TextField.html so how do I actually find what I want, as in which event does it trigger, how do I register the event handler? Or is it something that with time I will just know?
thanks

Violet_82 89 Posting Whiz in Training

OK thanks guys for all your help

Violet_82 89 Posting Whiz in Training

Uhm, well I have version 7, so it would be ideal if I can keep working on that

Violet_82 89 Posting Whiz in Training

The problem you have is that the indexes of the buttons in the array do not correspond directly to the numeric values the buttons represent. You can easily fix that with an array of its that maps the actual numeric values to the indexes.

I thought of a possible fix, but I want to check whether it is doable. Basically in the for loop I printed the values of each array element and the counter

for( int counter = 0; counter < labels.length; counter++ ){
    numberKey = new JButton( labels[ counter ] );//create button with apppropriate label
    numberKeysPanel.add( numberKey );//add buttons to panel
    numberKey.addActionListener(new ButtonHandler(counter));//create event handler
    System.out.println("labels[counter] " + labels[counter] + " print the counter " + counter  );
}//end of loop

That's so I get an idea of what is what. Then I am thinking that with a switch statement I could change the arrai index to match the label, meaning, in the loop I can test the button label and if it is = to 7 then change its index to 7 and so on.

Violet_82 89 Posting Whiz in Training

HI all, I am very new to LESS, literally just started today. I had a look at some tutorials, and got my first LESS webpage - or should I say CSS - to work in Firefox, but when I moved to other browsers the CSS doesn't pick up any style. SO I re-compiled the CSS again (I am using SimpleLess) but still no browser picks up the styles. I don't think there is anything wrong with the code, it is just a simple page with a few divs and a small css:

<!DOCTYPE html>
<html>
    <head>
        <title>LESS test</title>
        <link rel="stylesheet/less" type="text/css" href="style.less">
        <script src="less-1.7.0.min.js" type="text/javascript"></script>
    </head>
    <body>
        <div class="normalDiv"><p>This is a div</p></div>
        <div class="bigDiv"><p>This is a big div</p></div>
    </body>
</html>

CSS style.less here

@myColorSmall:#affaaa;
@myColorBig: #cccccc;
.sample-mixin{
    border:1px solid red;
    color:red;
    margin:5px;
}
@myBorder: 4px solid red;


.normalDiv{
    width:200px;
    height:200px;
    background-color:@myColorSmall;
}
.bigDiv{
    width:300px;
    height:300px;
    background-color:@myColorBig;
}
p{
    .sample-mixin;
}

Curiosuly, IE11 in the console says:

SCRIPT5: Access is denied.
File: less-1.7.0.min.js, Line: 13, Column: 5978

IE10 and IE9** work OK**, I can see the styles

IE8 and IE7 (no style shown) kindly notify me that:

SCRIPT438: Object doesn't support property or method 'bind'
File: less-1.7.0.min.js, Line: 13, Column: 27892

Chrome (no style shown) says:

less: XHR: Getting 'file:///C:/Users/.../LESS/style.less' less-1.7.0.min.js:13
XMLHttpRequest cannot load file:///C:/Users/.../LESS/style.less. Cross origin requests are only supported for HTTP. test.html:1
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/.../LESS/style.less'. less-1.7.0.min.js:13

Opera (no styles shown) …

Violet_82 89 Posting Whiz in Training

Eh, what does that even mean? Can you rephrase and post some code please?

Violet_82 89 Posting Whiz in Training

OK sorry, yes I made some changes now and it works, in that it returns the index of the position occupied by the key.

String[] labels = { "7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0", ".", "=", "+" };
        numberKeysGrid = new GridLayout( 4, 4, 5, 5 );//create grid layout

        //ButtonHandler handler = new ButtonHandler();

        for( int counter = 0; counter < labels.length; counter++ ){
            numberKey = new JButton( labels[ counter ] );//create button with apppropriate label
            numberKeysPanel.add( numberKey );//add buttons to panel
            numberKey.addActionListener(new ButtonHandler(counter));//create event handler
        }//end of loop




private class ButtonHandler implements ActionListener{
        int buttonNumber;
        public ButtonHandler(int b){
            buttonNumber = b;
        }
        public void actionPerformed( ActionEvent event){
            System.out.println("Handling event for button " + buttonNumber);
        }
    }

To return the actual number pressed, I am not sure I got that. I declare a new variable private int numberEntered; and change the actionPerformed:

public void actionPerformed( ActionEvent event){
            numberEntered = numberEntered*10 + buttonNumber;
            System.out.println("Handling event for button " + numberEntered);
        }

But this expression is interpreted as a string numberEntered = numberEntered*10 + buttonNumber; so the digits are added up as a string.

Violet_82 89 Posting Whiz in Training

thanks, @mKorbel I don't think I need the key support for this, but thanks.
I have implemented the above but now I get an error

CalculatorLayout.java:35: error: constructor ButtonHandler in class CalculatorLayout.ButtonHandler cannot be applied to given types;
                ButtonHandler handler = new ButtonHandler();
                                        ^
  required: int
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error

These are the amendments I have done:

numberKeysPanel = new JPanel();

        String[] labels = { "7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0", ".", "=", "+" };
        numberKeysGrid = new GridLayout( 4, 4, 5, 5 );//create grid layout

        ButtonHandler handler = new ButtonHandler();

        for( int counter = 0; counter < labels.length; counter++ ){
            numberKey = new JButton( labels[ counter ] );//create button with apppropriate label
            numberKeysPanel.add( numberKey );//add buttons to panel
            numberKey.addActionListener(handler);//create event handler
        }//end of loop
        numberKeysPanel.setLayout( numberKeysGrid );//attach grid layout to jpanel
        //set up GridLayout manager

so created the button handler and added the class:

}//end of constructor

    //class for event handling
    private class ButtonHandler implements ActionListener{
        int buttonNumber;
        public  ButtonHandler(int b){
            buttonNumber = b;
        }
        public void actionPerformed( ActionEvent event){
            System.out.println("Handling event for button " + buttonNumber);
        }
    }

}//end of CalculatorLayout class

Why is it asking for an int?!

Violet_82 89 Posting Whiz in Training

Hi, I am trying to add an event handling feature to an old program I wrote.
Here is the relevant code:

public class CalculatorLayout extends JFrame{
    private BorderLayout layout;//layout object. Do I need a flowlayout at all?
    private JPanel numberKeysPanel;//contains the number keys panel
    //private JPanel calculationAreaPanel;//contains the calculation panel
    private GridLayout numberKeysGrid;//contains the number keys
    private JTextField calculationArea;//text field where numbers are displayed
    private JButton numberKey;//symbols
    private String[] labels;//hold the labels



public CalculatorLayout(){
        super( "Calculator" );
        layout = new BorderLayout( 0, 5 );//create FlowLayout. Do I need a flowlayout at all?
        setLayout( layout );    
        calculationArea = new JTextField( "", 30 );//created empty display

        numberKeysPanel = new JPanel();

        String[] labels = { "7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0", ".", "=", "+" };
        numberKeysGrid = new GridLayout( 4, 4, 5, 5 );//create grid layout

        for( int counter = 0; counter < labels.length; counter++ ){
            numberKey = new JButton( labels[ counter ] );//create button with apppropriate label
            numberKeysPanel.add( numberKey );//add buttons to panel
        }//end of loop
        numberKeysPanel.setLayout( numberKeysGrid );//attach grid layout to jpanel
        //set up GridLayout manager

        //numberKeysPanel.add( numberKeysGrid );//add grid to jpanel
        add( calculationArea, BorderLayout.PAGE_START );//add calc area txt field to jframe
        add( numberKeysPanel, BorderLayout.CENTER );//add jpanel to the jframe      
    }//end of constructor

Now, I was just adding the even handling code, but I was wondering, since the buttons are created in a loop there is no way that I can use .addActionListener to each button unless I do that in …

Violet_82 89 Posting Whiz in Training

Hi, I have a question about animating anchor links with jquery. I had a look online
and for some hints and then I came up with this code:
HTML

<div class="navWrapper">
    <img src="images/mobile_quick_nav.png" alt="">
    <ul>
        <li><a href="#num1" class="navLink">Home</a></li>
        <li><a href="#num2" class="navLink">Panel 2</a></li>
        <li><a href="#num3" class="navLink">Panel 3</a></li>
        <li><a href="#num4" class="navLink">Panel 4</a></li>
        <li><a href="#num5" class="navLink">Panel 5</a></li>
        <li><a href="#num6" class="navLink">Panel 6</a></li>
    </ul>

</div>
...
<div class="panel" id="num1">
    <div class="intro">
        <h1>Test area</h1>
    </div>
    ...

<div class="panel" id="num2">
    <h2>Panel 2</h2>
    <p>Lorem ipsum dolor sit 
    ...
<div class="panel" id="num3">
    <h2>Panel 3</h2>
    <p>Lorem ipsum dol
    ...

and so on.
The script is:

var navWrapperHeight = $(".navWrapper ul").outerHeight();
$(".navWrapper ul li a").click(function(e){
        e.preventDefault();

        console.log("this.hash is " + this.hash);//returns the #* portion of the link
         $('html,body').animate({
                scrollTop:$(this.hash).offset().top - navWrapperHeight 
            }, 500);
    }); 

Now, the script confuses me slightly. I am grabbing all the links in the navigation and when I click on them I animate the scrolltop property of the html and body. But in this line scrollTop:$(this.hash).offset().top - navWrapperHeight
shouldn't this refer to the item that I am animating (therefore html and body and their offset top) rather than the link
I clicked on?

Violet_82 89 Posting Whiz in Training

Hi guys, I wonder if you can help me at all, I am a bit stuck here.
Having this HTML:

<div class="formWrapper">
<h2>Form box</h2>
<div class="unstyledForm">
<p>These form fields have minimal styles applied to it, so that tehy look the same in every browser and device</p>
<div class="row">
<label class="control-label" for="email">Email address<span class="mandatory"> *</span>
</label>
<div class="controls">
<input id="email" type="text">
</div>
</div>
<div class="row">
<label class="control-label" for="address">Address<span class="mandatory"> *</span>
</label>
<div class="controls">
<input id="address" type="text">
</div>
</div>
<div class="row">
<label class="control-label" for="memorableQuestion">Memorable question<span class="mandatory"> *</span>
</label>
<div class="controls">
<select id="memorableQuestion">
<option value="date">Memorable date</option>
<option value="pet">Memorable pet</option>
</select>
</div>
</div>
<div class="row">
<label class="control-label" for="address">Address 1
</label>
<div class="controls">
<input id="address" type="text">
</div>
</div>
</div>
</div>

I am trying to add a span with a class of noWrap around the last word and the asterisk, to prevent it from wrapping on the following line.
Now, the approach I was trying to use - which perhaps isn't the best one - was to first of all test whether the page has any label with an asterisk. If so look for the labels that contain the asterisk and add a span around them. Now, I didn't get past the first stage. Here is my script so far:

$(document).ready(function(){
    //alert("ohi");

    var isAsterisk = $(".mandatory").length;
    console.log("isAsterisk " + isAsterisk);
    if(isAsterisk){//if there are asterisks     
        var $asterisk = $(".row .control-label").find(".mandatory");//find the asterisk
        var words = $asterisk.parents(".control-label").text().split(" ");//select the label with asterisk get the text and put each word in an array
        for(var …
Violet_82 89 Posting Whiz in Training

OK cool, thanks I will give it a go!

Violet_82 89 Posting Whiz in Training

I am finally back after quite some time, and unfortunately I have lost quite a bit of what I have learned...
Anyway, I went back through my notes and old posts and messed around with the GridBagConstraints again, and I have a few questions.
This is the latest version of a 5x1 grid of buttons (screenshot attached a13ff6405069e860bd5ae6f43e5798f3 )

/*TestingGridBag.java*/
import java.awt.GridBagLayout;//chosen JFrame layout
import static java.awt.GridBagConstraints.*;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;//for radio buttons

public class TestingGridBag extends JFrame{
    private GridBagLayout layout;
    //private JPanel panel;
    private JButton okButton;
    private JButton cancelButton;
    private JButton submitButton;
    private JButton test1Button;
    private JButton test2Button;

    public TestingGridBag(){
        super("GridBagLayout test");
        layout = new GridBagLayout();
        setLayout( layout );//set layout of JFrame

        //panel = new JPanel();
        okButton = new JButton("OK");
        cancelButton = new JButton("Cancel");
        submitButton = new JButton("Submit");
        test1Button = new JButton("test1");
        test2Button = new JButton("test2");

        add( okButton, new GridBagConstraints( 0, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 20), 0, 0 ) );
        add( cancelButton, new GridBagConstraints( 2, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 20), 0, 0 ) );
        add( submitButton, new GridBagConstraints( 4, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 20), 0, 0 ) );
        add( test1Button, new GridBagConstraints( 6, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 20), 0, 0 ) );
        add( test2Button, new GridBagConstraints( 8, 0, 1, 1, 0, 0, CENTER, NONE, …
Violet_82 89 Posting Whiz in Training

Hi guys,
I was thinking to work on a new interactive project but I might need some advice before I start. So, essentially, I want an interactive map and I want to give users (they will have to have login details of course) the possibility to add as many markers as they want to it and a small description. I think this should be easy enough to achieve by using google maps mapmaker. I will create an account and give the login details away as needed. I still don't know whether I want to embed the map in a HTML page or not and content manage it with something like wordpress, I will decide that later.
In terms of the map, do you guys have any advice or suggestion, and can you think of possible issues? I assume that won't involve any specific experience, software skills as such? I am happy to use an already available product rather than develop a new one.

Violet_82 89 Posting Whiz in Training

cool thanks, it's interesting the usage of (":visible") and (:hidden). I would have used something like .css("display") to gauge whether the div in question is either block or none, and I did and found it that it doesn't work. The reason is fairly obvious: if I click on the header when the hiddenContent is visible .css("display") will still return "block" because when I clicked on the header the content will still be visible if that makes sense. So I take (":visible") and (":hidden")work in a different way?

Violet_82 89 Posting Whiz in Training

Hi all, I wonder if somebody can help me with this. I have this situation:
I have a header div with a heading and when I click on it another div hiddenDiv slides down or slides up (I am using the slideToggle method). What I want to do also is to change the background image on the header div, depending on whether the hiddenDiv is collapsed or not. Let's have a look at the code:

HTML

<div class="wrapper">
    <div class="header"></div>
    <div class="hiddenDiv">
        <p>I am displayed/hidden when user clicks on header</p>
    </div>   
</div>

SCRIPT

$(document).ready(function(){
    $(".header").click(function(){
        $(this).siblings("hiddenDiv").slideToggle("fast");
    });
});

Assuming the header div needs to have a "+" background image when the hidden div is collapsed and a "-" when it is open, what would be the best ay to implement this with the slideToggle method?
I was thinking - but I am open to suggestions of course - to have two more classes:

.plus{
    background: #fffff url("plusSign.jgp") no-repeat 100% 0;
}
.minus{
    background: #fffff url("minusSign.jgp") no-repeat 100% 0;
}

and then add them in the script like this:

$(document).ready(function(){
    $(".header").click(function(){
        var $thisHiddenDiv = $(this).siblings("hiddenDiv")
        $thisHiddenDiv.slideToggle("fast");
        if($thisHiddenDiv:visible){
            $(this).removeClass("plus").addClass("minus");
        }
        else{
            $(this).removeClass("minus").addClass("plus");
        }
    });
});

Would that work? Unfortunately I don't have any code to try it on right now, the above is just a demonstration.
cheers

Violet_82 89 Posting Whiz in Training

Right, another question.
Just to pick up on something said before about a cell being empty in the layout:

Not that I know of. Just don't put anything in it!
SOmetimes I have had dynamic form contents where I have (eg) added buttons at 1,0 2.0 and 999,0 so I can later add buttons after the first two, but before the last one. The unused columns just get a zero width.

I thought I'd replicate this layout now:
c74171e15b0fbe52c7a8b9d19542064d
So I changed my code accordingly:

 add( okButton, new GridBagConstraints( 0, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 0), 0, 0 ) );
add( cancelButton, new GridBagConstraints( 2, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 0), 0, 0 ) );
add( submitButton, new GridBagConstraints( 4, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 0), 0, 0 ) );
add( test1Button, new GridBagConstraints( 6, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 0), 0, 0 ) );
add( test2Button, new GridBagConstraints( 8, 0, 1, 1, 0, 0, CENTER, NONE, new Insets( 0, 0, 0, 0), 0, 0 ) );

I have modified the coordinates in an attempt to produce an empty cell between the buttons, but nothing gets displayed. Now, I assume this happens because, as it has been pointed out before, the width of an empty column (and in this case having only one row the empty cell effectively represents a column) is 0. So how do I get around this? SHould I use the inset values perhaps?
thanks

Violet_82 89 Posting Whiz in Training

I don't disagree with you at all, but I doubt I will ever develop something big. That said, I hope to learn the basics of layout (which will involve doing things from scratch) and then perhaps moving a GUI.

Violet_82 89 Posting Whiz in Training

ah, good news, with a few changes here and there now I got it to work. I had to take out the click handler and wrap it inside a document.ready() though

var form = { //object literal
    init: function(){       
        console.log($(this) + "function called");       
    }   
};
$(document).ready(function(){
    $(".theButton").click(function(){
        form.init();
    });
});
Violet_82 89 Posting Whiz in Training

yep that's what I generally do too :-), but this object literal thingy bugged me, that's why I thought I'd give it a go...and I wasn't that successful I must say!

Violet_82 89 Posting Whiz in Training

iamthwee, as far as I am concerned I want to learn how to use the layout managers although I have to say that I am not a programmer so I find extremely hard to grasp concepts that for a programmer are instead obvious. Using a GUI builder will be much easier I am sure, especially for me, but then I will have absolutely no clue as to how things happen. I am not trying to get to a point that I can master all the possible layouts, but I came to realize (ahem!) that the GridBagLayout is extremely useful and powerful (and I'd throw in complicated too) and therefore I think that as a beginner java developer I must learn to use it, at least the basics.

Violet_82 89 Posting Whiz in Training

Cool Ok thanks.

Not that I know of. Just don't put anything in it!

I would have thought that if a cell is empty then its width would be 0 pretty much like an empty column if you like.