0

CODING CLUB: Challenge 1

Okay so for this challenge you need to print "hello world" Comment how you did it below... (Plus I want this to be organised by everyone not just me, so feel free to post new challenges etc.) Everything to do with the coding club must be tagged on codingclub GOOD LUCK!!! šŸ’•

29th Jul 2016, 9:07 PM
codingismylife145
codingismylife145 - avatar
18 Respostas
+ 2
Just to be helpful though, I'll simplify your program. import javax.swing.*; import java.awt.event.*; public class MyFirst extends JFrame implements ActionListener{ JButton button; public static void main(String[] args){ MyFirst gui = new MyFirst(); gui.go(); } public void go(){ button = new JButton("Click here"); button.addActionListener(this); getContentPane().add(button); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(100, 100); setVisible(true); } public void actionPerformed(ActionEvent event){ button.setText("Hello World"); } }
30th Jul 2016, 3:41 AM
James
James - avatar
+ 1
public class Program { public static void main(String[] args) { System.out.println("Hello World!"); // Prints "Hello World!" } } :D
12th Aug 2016, 12:21 AM
7FX
7FX - avatar
+ 1
import javax.swing.*; import java.awt.event; public class HelloWord extends JFrane implements ActionListener{ public HelloWord(){ super("Hello word"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton cb = new JButton("Button"); JTextArea ta = new JTextArea(10, 11); JPane pane = JPane(); pane.add(cb); pane.add(ta); add(pane); setVisible(true); } public void actionPerformed(ActionEvent event){ Object source = event.getSource(); if(source.equals(cb)){ ta.setText("Hello World"); } public static void main(String [] args){ HelloWorld h = new HelloWorld(); } }
25th Jun 2019, 9:11 AM
Michel Nyembo Chungu
Michel Nyembo Chungu - avatar
0
I'm going to answer this sith a simple "hello world" program. but after I'm going to try and make a box with button, and when pressed it pops up "hello world". //start of code public class Myfirst { public static void main(String[] args) { System.out.println("hello world"); } } //code ends very simple. my second attempt should look a little better.
29th Jul 2016, 11:02 PM
Barra
Barra - avatar
0
Barra, one thing with your code to pick at. You should use MyFirst when naming your class, in order to follow java standard naming convention.Other then that, good job.
30th Jul 2016, 12:51 AM
James
James - avatar
0
James, all tips are welcome, thanks :) I might take a while with this pub up box with Jframe and JButton. back to the drawing board.
30th Jul 2016, 1:16 AM
Barra
Barra - avatar
0
ok so getting the button was the easy part. using ActionListener I had a bit of a struggle. I'll need to work on it. I've posted it to paste bin - http://pastebin.com/B3Twu2h4
30th Jul 2016, 2:44 AM
Barra
Barra - avatar
0
Barra, if I may make a recommendation based on reading your code. Go back to basics. I could be wrong, but it looks like you're jumping from hello world to a JFrame and ActionListener program. That's a huge leap, you're probably copying and pasting your code and not entirely sure what it's doing? If that's the case, don't jump so far ahead. Keep learning the basics, eventually you'll stumble on Inheritance and Interface implementation, at that point your code will make sense and you won't get so hung up on it.
30th Jul 2016, 3:29 AM
James
James - avatar
0
Yeah I think your right as I had to keep looking up how to do things. my code was a complete mess and I can't believe how easy you made it look!!
30th Jul 2016, 4:19 AM
Barra
Barra - avatar
0
I've been there man. I've stopped and started programming several times throughout the years. I've done the same things other people do, so I generally know what's going on. Jumping too far ahead has led to a lot of frustrations that, looking back, could have been solved by just taking it slower and making sure I knew what I was doing. Rushing to learn as fast as possible is generally a setup for failure.
30th Jul 2016, 4:22 AM
James
James - avatar
0
James, a small correction In the import statement, it's import javax.swing.*; not javac.swing.*;
30th Jul 2016, 5:41 PM
Vamsi Manepalli
Vamsi Manepalli - avatar
0
And Barra, I learnt Java from thenewboston and I did the exact same thing...it's completely correct
30th Jul 2016, 5:42 PM
Vamsi Manepalli
Vamsi Manepalli - avatar
0
Fixed. Lotta code to write on a phone, was bound to make a mistake somewhere
30th Jul 2016, 6:00 PM
James
James - avatar
0
Yeah I learnt from TheNewBoston also but I'm a bit too far ahead on the videos as I couldn't write most of that code on my own. I'm going to put up a second challenge. I prefer James code as it's a lot simpler.
30th Jul 2016, 8:05 PM
Barra
Barra - avatar
0
public class printHello { public static void main(String[] args) { System.out.println("Hello World!"); } }
30th Jul 2016, 11:24 PM
Dmitry
Dmitry - avatar
0
Keep in mind, my code was simplified for a teaching example. The code you were writing was going towards a much more efficient program with the frame and handler being separated into classes. But, if you're not sure what's going on, writing a bit of less optimized code can help get a better understanding.
31st Jul 2016, 1:44 AM
James
James - avatar
0
Can't deny that James!
31st Jul 2016, 3:55 AM
Vamsi Manepalli
Vamsi Manepalli - avatar
0
class Shyam { class public void main(String s[] ) { System.out.println("hello world"); } }
5th Aug 2016, 2:30 PM
Shyam sunder Reddy
Shyam sunder Reddy - avatar