Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Not all code is developed in the same environment. Let's learn how to bring in outside project into our shiny new IDE.
Project Files
- In the course downloads zip file, use the Karaoke Project
Additional Reading
-
0:01
Okay, so remember that quiz question from a previous
-
0:03
course where I asked about a dunk tank?
-
0:05
Well some of you didn't know what that was and I apologize.
-
0:08
It's a carnival game where someone sits over a pool of water on a shelf.
-
0:12
The carnival-goer buys the balls and they throw it at the target.
-
0:16
If they hit the target, the person falls into the water.
-
0:20
Now I'm sure you're imagining putting me on that dunk tank and
-
0:23
throwing the ball and having me dunked into freezing cold water,
-
0:27
because I didn't show you these tools earlier.
-
0:29
But, before you get too upset at me, let's take a second to appreciate that you were
-
0:33
able to code in Java without these tools.
-
0:36
You didn't need these training wheels on your editor.
-
0:38
Let's be honest, most of the warnings wouldn't have made any sense to you at
-
0:42
all until you got started.
-
0:44
Now, that being said though, you can totally dunk me.
-
0:47
I'm sure I deserve it.
-
0:48
I did make you type a lot more than you would have to in a real world situation.
-
0:52
So let's just say at this point, I definitely owe you three dunk tank balls.
-
0:56
Alright, so let's import that very long project that you painstakingly
-
1:01
completed without code assistance in the previous course, the karaoke machine.
-
1:06
I want to show you how to bring outside code into this new world order.
-
1:10
Okay, so I've included a zip file of
-
1:13
the source code from the final project in the teacher's notes.
-
1:16
If you want to get your own version, just go to your workspace and choose File >
-
1:20
Download Workspace, and that will send down a ZIP file that you can then open up.
-
1:24
So what I've done is I've downloaded that ZIP file, I've unzipped it, and
-
1:26
now I have that source code in a folder.
-
1:28
Here it is.
-
1:30
Now, since we're just hand coding like this and there isn't
-
1:32
any additional project information, let's first just create a new project.
-
1:37
Okay. So, the way that you do that is,
-
1:38
in IntelliJ you choose File > New > Project.
-
1:43
Okay. And this is very much like the Create New
-
1:45
Project that we saw before, and we wanna just leave it, the Project SDK the same.
-
1:50
We don't wanna do a template, right?
-
1:51
Because we've already got our code that we need, so we're just gonna go ahead and
-
1:54
leave that unchecked.
-
1:56
And we're gonna call this Karaoke.
-
2:01
Okay. So, it's possible to have multiple windows
-
2:04
open with different editors and that's what this prompt is asking.
-
2:07
It's asking if we want to replace this window or if we wanna make a new one and
-
2:11
have them side by side.
-
2:12
For our case, we're just gonna use this one.
-
2:14
So what it's gonna do is it's gonna get rid of the systemizer window that we have
-
2:17
and we're gonna put up the karaoke window.
-
2:20
Cool.
-
2:21
So, this is an empty project.
-
2:24
By default, the project is set up in a directory based format.
-
2:27
When creating a project, a default module is added for us, and
-
2:31
that's what this is here, this karaoke.
-
2:33
Now a module in IntellaJ is defined as a discreet unit of functionality.
-
2:38
Modules contain everything that is required for there specific task, and
-
2:43
they come with an idea folder.
-
2:44
This .Ideafolder.
-
2:46
It contains files about how you like your editor setup.
-
2:49
They also have an IML file here, and
-
2:51
it keeps project specific settings in one place.
-
2:54
The .iml suffix stands for idea module, and the fact that all the settings are in
-
2:59
a file like this, it makes sure that teams can have the same setup.
-
3:02
So I could share this with somebody else and this setup would be the same.
-
3:06
There's a little icon on this folder here, on the karaoke folder here of this module.
-
3:11
And that's saying that its the content root folder.This source folder here
-
3:16
is short for source code.
-
3:18
And its blue you'll notice, and that blue represents that its the source root.
-
3:22
All other folders are sort of orange and yellow like that.
-
3:26
If you're working with other projects from idea users or even in clips projects,
-
3:30
you can actually import things really easy.
-
3:32
So, you could get these INL files from other people like I was saying.
-
3:36
But what I wanna show you here first is that when you don't
-
3:39
have an existing idea project to import, like we don't currently, right?
-
3:42
Our karaoke project is hand-coded.
-
3:44
You can imagine this as kind of converting or upgrading to an idea project.
-
3:49
These idea projects respond really well to dragging and dropping.
-
3:53
So, I'm gonna go ahead and I am gonna grab the karaoke folder and our packages.
-
3:59
And I'm gonna drag those and
-
4:01
I'm gonna just click right inside the source file here, okay?
-
4:05
And it's gonna go ahead and say move the specified references and
-
4:07
that's fine, right?
-
4:08
Cuz that was just a zip folder that I had.
-
4:09
So I'm just gonna go ahead and move them.
-
4:11
And it says open the moved files in the editor.
-
4:13
Sure, why not?
-
4:15
Okay, and it says they don't belong to the project.
-
4:18
Okay I understand that.
-
4:19
I'm moving them.
-
4:22
And finally, I'm gonna bring this songs.text to the content root.
-
4:27
Right? So I'm gonna put it here.
-
4:28
When we end up running this later and
-
4:30
again it asks for the same things here again.
-
4:32
Before we were running right from the start of the directory and
-
4:36
this is relative.
-
4:37
We'll explore this a little bit in the future when we go to run this.
-
4:41
But I just wanted to point out that we don't want to drop it into source code
-
4:44
folder, we're gonna put it in the content root, and I'll show you why here in a bit.
-
4:47
Okay, so, I really wanna show you something that's gonna make you happy.
-
4:52
So, you can set up these different formatting rules.
-
4:55
So, here's our song.java file.
-
4:57
Now let's say that when we were coding,
-
4:59
we weren't the cleanest about things about things that we kind of did.
-
5:03
We move this over, got a warning up here about the file is indented with
-
5:09
two spaces instead of four, and that's kind of the default here, in this world.
-
5:12
And this is nice, right?
-
5:14
Cuz if you have different team members working on different things.
-
5:16
So, I'm just gonna screw up the spacing a little bit because, you know,
-
5:19
we were rushing to get through this before and the spacing wasn't quite done.
-
5:23
So, let's go ahead and come up here to code.
-
5:28
And if you look down here in this code, there's this Reformat code,
-
5:35
and that is Option+Command+L on a Mac.
-
5:39
So I'm gonna go ahead and I'm gonna click that.
-
5:40
Watch what it does.
-
5:42
Boom. Everything got set the proper way and
-
5:44
now it's also at four spaces.
-
5:45
But look, everything's back to where it was.
-
5:47
So, I am gonna do that again and I'm gonna do that again and
-
5:51
we'll just bring this guy.
-
5:54
It's pretty good at not letting me screw those up.
-
5:57
So, I'm going to Option+Command+L and everything is back to normal.
-
6:02
So it's Ctrl+Alt+L in Windows.
-
6:03
That's great.
-
6:04
But what if I knew that I remembered doing that one time, but
-
6:08
I can't remember where it's at?
-
6:09
So there's a great feature in IntelliJ whic will be your friend,
-
6:12
especially when you're learning this.
-
6:14
If you press Cmd+Shift+A, or Shift+Ctrl+A on Windows, and you choose.
-
6:22
I know it wasn't Reformat.
-
6:25
There it is, Reformat Code.
-
6:26
And then, boom.
-
6:27
And it will do it.
-
6:29
And I have to break anything, let's break something real quick.
-
6:34
So, Control+Shift+A, Reformat Code, boom, that fixed it.
-
6:38
Great, right?
-
6:39
So, we just did this file, but let's go ahead and open up another file over here.
-
6:44
Let's open up Songbook.
-
6:46
So we can go ahead and reformat the entire package.
-
6:50
So, if I come up here to the source folder and I say Reformat Code,
-
6:57
we're gonna include subdirectories and we're gonna leave Optimize Imports, right?
-
7:01
So that's gonna remove any imports that we didn't use, cuz that can happen, and
-
7:05
we're also gonna choose Rearrange Entry.
-
7:07
So, I'm gonna click Run.
-
7:10
So, now all the files, and
-
7:12
we can open them up by clicking on them over here, are done.
-
7:16
You also notice there's some of these pluses.
-
7:18
This is here to kind of help you read your code quicker, but I'm gonna open this up.
-
7:23
One more thing I wanted to show you really quick is, on the imports over here,
-
7:26
remember we put the dot star, and I told you it was a little bit lazy?
-
7:30
Well let's go ahead and let's put our cursor here and let's see what happens.
-
7:32
Look, there's a little thing that popped up over here.
-
7:34
This light bulb is called an intention action.
-
7:37
What happens with these intention actions are they're suggestions
-
7:40
of what could happen.
-
7:42
So, let's go ahead and open this up and it says, replace with single class imports.
-
7:46
That's great, that's exactly what we wanted.
-
7:47
We just didn't want to have to type all those out, so let's do that.
-
7:50
And what it did was it took an alphabetized order of everything that we
-
7:54
used in here that was under that star.
-
7:56
Pretty powerful tool, isn't it?
-
7:58
Okay, we learned a ton there.
-
8:00
And as I'm sure,
-
8:01
you saw when you opened that menu up, there are a lot more actions in there.
-
8:04
We definitely aren't gonna hit all of those, but in a bit, I'll show you how
-
8:08
awesome the documentation is for the IntelliJ Idea Project.
-
8:12
You can dive in at your own pace.
-
8:14
So let's go ahead and take a quick break and I'll swing back and
-
8:16
show you how to run our application.
You need to sign up for Treehouse in order to download course files.
Sign up