Head First Java, 2nd Edition

Author: Kathy Sierra, Bert Bates
4.3
All Stack Overflow 26
This Year Reddit 42
This Month Stack Overflow 1

Head First Java, 2nd Edition

4.3

Review Date:

Comments

by passthejoe   2018-03-19

Is this a class that teaches Java?

If so, the two books I have that I think are really good are "Head First Java" https://toptalkedbooks.com/amzn/0596009208 and the new "Computer Science: An Interdisciplinary Approach" https://toptalkedbooks.com/amzn/0134076427

Also, Oracle has a great Java tutorial that is available free on the web and as PDFs and ebooks: https://docs.oracle.com/javase/tutorial/

by ImEasilyConfused   2018-03-19

From OP:

>The exact four books I read are:

>Learning Obj-C

>Learning Java

>iOS Programming: The Big Nerd Ranch Guide

>Android Programming: The Big Nerd Ranch Guide

>However, I would now recommend learning Swift instead of Obj-C. At the time when I was looking into iOS books, good books on Swift were few and far between.

From u/AlCapwn351 in regards to other sources to learn from:

>www.codeacademy.com is a great site for beginners (and it's free). It's very interactive. W3schools is good for learning stuff like JavaScript and HTML among other things.

>When you get stuck www.stackoverflow.com will be a lifesaver. Other than that, YouTube videos help and so do books. Oh and don't be afraid to google the shit out of anything and everything. I feel like an early programmers job is 90% google 10% coding.

>Edit:

>It's also good to look at other peoples code on GitHub so you can see how things work.

by ImEasilyConfused   2018-03-19

From OP:

>The exact four books I read are:

>Learning Obj-C

>Learning Java

>iOS Programming: The Big Nerd Ranch Guide

>Android Programming: The Big Nerd Ranch Guide

>However, I would now recommend learning Swift instead of Obj-C. At the time when I was looking into iOS books, good books on Swift were few and far between.

From u/AlCapwn351 in regards to other sources to learn from:

>www.codeacademy.com is a great site for beginners (and it's free). It's very interactive. W3schools is good for learning stuff like JavaScript and HTML among other things.

>When you get stuck www.stackoverflow.com will be a lifesaver. Other than that, YouTube videos help and so do books. Oh and don't be afraid to google the shit out of anything and everything. I feel like an early programmers job is 90% google 10% coding.

>Edit:

>It's also good to look at other peoples code on GitHub so you can see how things work.

by anonymous   2017-08-20

Head First Java is a great place to start.

Head First Java

by anonymous   2017-08-20

Your question is how to pass information from one JFrame to another, and this can be done as simply as having one class call a method of the other class. That you haven't done this, and that you've only posted a skeleton program, one with components but with no logic suggests to me that you are still very much a beginner Java programmer, and so my main suggestion is that first and foremost you strive to learn to code, and in particular learn about object oriented principles and how they relate to Java. Without these rudiments under your belt, we can give you code and pointers, but it won't help you much. I suggest that you go to the Java Tutorials and start there, but also that you get a decent book or two on the subject such as Bruce Eckel's Thinking in Java, and/or Head First Java.

As for your actual code I suggest that you not create classes that extend JFrame since that locks you into a JFrame, and again as per my comment above, your tool window should be a non-modal JDialog not a JFrame. If you gear your code towards creating JPanels, then you can place them into JFrames, JDialogs, other JPanels, etc... wherever needed, and so this gives you a lot more flexibility.

The main difficulty in the situation of your program is not passing information from one window to another, one object to another, really, but rather when to do so, since the program is event driven. Myself, I like to use PropertyChangeListeners for this, basically using an observer interface that is already part of the Swing GUI structure. For example in the code below I create two main JPanels, one is displayed within a JFrame, the other within a non-modal JDialog, and I pass button press information (the actionCommand String of the button) to the JTextArea in the main GUI via a PropertyChangeListener:

import java.awt.BorderLayout;
import java.awt.Dialog.ModalityType;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.*;

public class Foo3 {
    private static void createAndShowGui() {
        final MainPanel1 mainPanel1 = new MainPanel1();
        final ToolPanel1 toolPanel1 = new ToolPanel1();

        JFrame frame = new JFrame("Foo3");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(mainPanel1);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        JDialog dialog = new JDialog(frame, "Toolbar", ModalityType.MODELESS);
        dialog.add(toolPanel1);
        dialog.pack();
        dialog.setLocationByPlatform(true);
        dialog.setVisible(true);

        toolPanel1.addPropertyChangeListener(ToolPanel1.ACTION_COMMAND, new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                mainPanel1.appendActionCommand((String) evt.getNewValue());
            }
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGui();
            }
        });
    }
}

class MainPanel1 extends JPanel {
    private JTextArea actionCommandArea = new JTextArea(30, 50);
    private JScrollPane scrollPane = new JScrollPane(actionCommandArea);

    public MainPanel1() {
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

        setLayout(new BorderLayout());
        add(scrollPane, BorderLayout.CENTER);
    }

    public void appendActionCommand(String text) {
        actionCommandArea.append(text + "\n");
    }
}

class ToolPanel1 extends JPanel {
    public static final String ACTION_COMMAND = "action command";
    public static final String[] BTN_TEXTS  = {
        "Select Element",
        "Insert Image",
        "Insert Text",
        "Insert Hyperlink",
        "Change Page Background",
        "Insert Textbox",
        "Insert Radio Button", 
        "Insert Checkbox",
        "Insert Horizontal Rule",
        "Insert Button",
        "Insert Drop-Down List",
        "Insert List",
        "Add Script"
    };
    private String actionCommand = "";

    public ToolPanel1() {
        int rows = 0; // variable number of rows
        int cols = 2; // 2 columns
        int hgap = 5;
        int vgap = hgap;
        setLayout(new GridLayout(rows, cols, hgap, vgap));
        setBorder(BorderFactory.createEmptyBorder(hgap, hgap, hgap, hgap));

        for (String btnText : BTN_TEXTS) {
            add(new JButton(new ButtonAction(btnText)));
        }
    }

    public String getActionCommand() {
        return actionCommand;
    }

    private class ButtonAction extends AbstractAction {
        public ButtonAction(String name) {
            super(name);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            String oldValue = "";
            String newValue = e.getActionCommand();
            actionCommand = newValue;
            ToolPanel1.this.firePropertyChange(ACTION_COMMAND, oldValue, newValue);
        }
    }
}

A more robust design would be to use a Model-View-Controller type design, but this is a bit more advanced, and you'll need to get some more code experience under your belt before using this, I think. also check out these links to similar questions/answers.

by anonymous   2017-08-20

In future you should post these sorts of questions on the Programmers Q&A site.

If you want to learn best practices your best bet is to learn from multiple sources. That way you see the content from multiple perspectives and that is the best way to gain your own perspective on the subject. You sound pretty keen on videos although to be honest I wouldn't recommend them. You can learn much more from written articles, tutorials and books like Head First Java and the official Java Tutorial etc. with examples and exercises. You cannot learn programming without doing it.

by anonymous   2017-08-20

A few things stood out to me as your goals:

  1. You want formal training on how to program (this is independent of a language)
  2. You want to learn how to develop apps for a mobile device
  3. Your boss is on board with goals 1 and 2, but wants to see the best return on her investment.

I think the easiest way for you to meet all of these goals is to start learning how to program with Java. Java is often used in introductory computer science courses, so you should be able to learn the language and programming concepts in parallel. Once you have that foundation, you will be able to start learning Android development, since Android applications are built with the Java language.

You can start off by reading some of the resources from Oracle: http://download.oracle.com/javase/tutorial/java/concepts/index.html

And there are plenty of good intro books too:

There is nothing wrong with starting off by learning Python. Once you have a good grasp of programming fundamentals, you can learn new languages relatively quickly. However, from your boss's perspective, there is more value in paying for you to learn a language for mobile development and programming at the same time.

by Bill the Lizard   2017-08-20

Head First Java is the best book for learning Java. It's an introduction to object oriented programming, as well as Java, so as an experienced programmer you might be better served by Thinking in Java.

by Fortyrunner   2017-08-20

You really need a copy of Head First Java

by shuman1981   2017-08-19

https://toptalkedbooks.com/amzn/0596009208

Yeah, it was a good quick read (one week at the beach) and the exercises were not mundane. It's great for visual learners as well if you're into that sort of thing.