Public, Protected, Default, and Private?
Here’s a chart
Class Subclass Package World
Public Y Y Y Y
Protected Y Y Y N
Nothing Y Y N N
Private Y N N N
I accidentally posted this from my main blog a while back.

❣ Chile in a Photography ❣
we're not kids anymore.

Origami Around
NASA

Janaina Medeiros
wallacepolsom

No title available
Keni

★

PR's Tumblrdome
RMH
d e v o n
noise dept.
Lint Roller? I Barely Know Her

titsay

shark vs the universe

pixel skylines
occasionally subtle

ellievsbear

No title available

seen from Lithuania

seen from Singapore

seen from Japan
seen from Ireland
seen from Germany
seen from United Kingdom
seen from Türkiye
seen from South Africa
seen from Australia
seen from Argentina

seen from United States

seen from Algeria
seen from Lithuania
seen from Jamaica

seen from Jamaica

seen from Malaysia
seen from South Africa
seen from United States
seen from United States

seen from United States
@simplejavacourse-blog
Public, Protected, Default, and Private?
Here’s a chart
Class Subclass Package World
Public Y Y Y Y
Protected Y Y Y N
Nothing Y Y N N
Private Y N N N
I accidentally posted this from my main blog a while back.
Libraries!
Libraries tend to involve a lot of just plain memorization. No tricks here.
One trick I do is adding a * to my import, which means all from this library.
If you want to work with a GUI you have to
import javax.swing.*;//This will include JFrame JPanel and many more
java.awt.*; is used for many graphics and keyboard tools
java.awt.event.*; is used for mouse events and key events and even button events.
java.util.*; is like the batman belt of Java I tend to use this with all real programming assignments because I just LOVE the ArrayList ^^
These are the ones I tend to use the most, but there are MANY MORE and it just takes time to learn the ones that apply to you.
Hey, what about something that uses an API, something like a simple Twitter tweeter app. And, welcome back :)
Sure thing, and thanks!Now just something that lets you log into your account, and send tweets in an input bar?Warning: This may be a series of tutorials, because I have to build you up to doing that.
NubecInfiniteArray
//We have to import the ArrayList class import java.util.ArrayList; //Making of a public class public class NubecInfiniteArray { //Main method public static void main(String[]args) { //We create a new ArrayList of Integers //Integers are different than ints //Integers can act like ints though ArrayList<Integer> list = new ArrayList<Integer>(); //We add an int 7,8,9 to the Array list.add(7); list.add(8); list.add(9); //We remove the 3rd element from the list //Remember we count like 0,1,2 list.remove(2); //A for each loop to print out all elements in the ArrayList //For Every Integer "i" in list // print "i" for(Integer i:list) System.out.println(i); } }
KeyboardListener
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class KeyboardEar { public static void main(String[]args) { JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setSize(200,200); window.setLayout(null); JPanel box = new JPanel(); box.setBackground(Color.BLACK); box.setBounds(20,20,20,20); box.setFocusable(true); box.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { JPanel panel = (JPanel)e.getSource(); Point pos = panel.getLocation(); int x = (int) pos.getX(); int y = (int) pos.getY(); switch(e.getKeyCode()) { case(KeyEvent.VK_UP):panel.setBounds(x,y-5,20,20);break; case(KeyEvent.VK_DOWN):panel.setBounds(x,y+5,20,20);break; case(KeyEvent.VK_LEFT):panel.setBounds(x-5,y,20,20);break; case(KeyEvent.VK_RIGHT):panel.setBounds(x+5,y,20,20);break; } } } ); window.add(box); window.setVisible(true); } }
NubecArray
public class NubecArray { public static void main(String[]args) { //We create an Array of 10 ints int[]array = new int[10]; //Unless set otherwise all elements = 0; //We set the 4th element in the array to 9 array[3] = 9; //You have to start counting from 0 //We'll use a for each loop to cylce through the elements for(int x:array) System.out.println(x); } }
Challenge Present: Internet Browser!
import java.awt.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; public class MyBrowser { private JFrame window; private JTextField urlBar; private JEditorPane display; public MyBrowser() { window = new JFrame("Krowser"); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setLayout(new BorderLayout()); window.setSize(1000,700); urlBar = new JTextField("http://www.google.com/"); urlBar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { load(e.getActionCommand()); } }); window.add(urlBar, BorderLayout.NORTH); display = new JEditorPane(); display.setEditable(false); display.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) load(e.getURL().toString()); } }); window.add(display, BorderLayout.SOUTH); window.setVisible(true); } public void load(String url) { try { display.setPage(url); } catch(Exception e) { //Nothing! } } public static void main(String[]args) { new MyBrowser(); } }
Grabbing user input
import java.util.*; public class Scanning { public static void main(String[]args) { Scanner scanner = new Scanner(System.in); System.out.println(scanner.nextLine()); } }
Ideas for lessons!
I would appreciate some ideas as to what to teach you guys. I've installed disqus, so please leave a comment below!
Are you guys finding these tutorials useful?
Adding HTML to a window
import javax.swing.*; public class HTML { public static void main(String[]args) { JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setSize(200,200); window.setLayout(null); JLabel label = new JLabel("<html><h1>Hello World!</h1></html>"); label.setBounds(20,0,200,50); window.add(label); window.setVisible(true); } }
Teaches you how to make, compile, and run your first java project!
IDE's for different OS's
Windows: BlueJ, Notepad++
Linux: Geany
Mac:TextMate
To be continued then broken
public class ContinueAndBreak { public static void main(String[]args) { for(int i=0;i<10;i++) { if(i==4)continue; System.out.println(i); } System.out.println(); for(int i=0;i<10;i++) { if(i==4)break; System.out.println(i); } } }
Commenting and Youtube Uploads
I've decided against the Javadoc'ing process and will instead make Youtube videos. I will post the uploads as they come.
Commenting Update
So I'm going to work on giving all the codes Javadocs.
Javadocs aren't nessisary to the actual code itself, but it'll help you know what on earth is going on with this sorcery.
Think of Javadocs as fancy comments
JC-C-C-ComboBox!
import javax.swing.*; import java.awt.event.*; public class ComboBox { public static void main(String[]args) { JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setSize(200,200); window.setLayout(null); String[]opts = {"Option 1","CheeseBurger","Taco"}; JComboBox<String> opt = new JComboBox<>(opts); opt.setBounds(25,60,150,25); opt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox)e.getSource(); System.out.print(cb.getSelectedIndex()+": "); System.out.println(cb.getSelectedItem()); } }); window.add(opt); window.setVisible(true); } }