fontBox = new JComboBox(fonts); fontBox.addActionListener(this); fontBox.setSelectedItem("Arial");
// ------ menubar ------
menuBar = new JMenuBar(); fileMenu = new JMenu("File"); openItem = new JMenuItem("Open"); saveItem = new JMenuItem("Save"); exitItem = new JMenuItem("Exit");
38:58 the reason this guy is the best, out of 10 different playlists, with 100 or more videos in each with every each one having a duration of 10 min or more, he isnt bored and he still leaving amazing tuturial details like this one, its like even if u wanted to find this clip of him messing around with the fontSizeSpinner that he created, u couldnt, its so deep hidden but yet ultra entertaining
"Welcome to my desktop everybody" with a tinge of embarrassment like someone touring their house and showing their not so messy room as messy. Fucking love it lol.
Thank you, wonderful tutorial! I was able to follow along quite easily. I don't know if it's a project or a funny name for a tutorial or smth, but I couldn't help but laugh when noticing a folder named 'Nuclear launch codes' in your desktop.
@Bro Code i really like this tutorial u made :) but i think u should make a "find" function,im also making a option that makes the framecolor yellow,black,or white (includes textarea)
There is another way to read the text in a file , which you have mentioned before in file reader . /* // another style public void open() {
fileChooser = new JFileChooser() ; fileChooser.setDialogTitle("Open file") ; fileChooser.setCurrentDirectory(new File("./src")) ; // filter out the files that don't have specific extension name (.txt) . FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files" , "txt") ; // (title , file extension name) fileChooser.setFileFilter(filter) ;
// show the window for opening file . int response = fileChooser.showSaveDialog(null) ; // if [Open] is pressed or [file] is double clicked . if (response == JFileChooser.APPROVE_OPTION) {
// get the absolute pathname of opened file . File file = new File(fileChooser.getSelectedFile().getAbsolutePath()) ;;
FileReader reader ;
// if opened file is file , not folder . if (file.isFile()) { try { reader = new FileReader(file) ; // clean the textArea before you add file text on it . textArea.setText("") ; int data = reader.read() ;
while (data != -1) { textArea.append(String.valueOf((char)data)) ; data = reader.read() ; }
// it's a good behavior to close I/O stream when not in use . reader.close() ;
openedfileText = textArea.getText() ; // remind user the open process has finished . JOptionPane.showMessageDialog(null , "You have opened successfully .") ; } catch (IOException e1) { e1.printStackTrace(); } } } } */
your code is correct but in full mode menubar not display correctly can you please do this in netbeans ide where we can design the layout first then code it for logic. rest things is good.
Hey!! I was wondering how to make a button that bolds and un-bolds the textArea. I made it so that it will bolden it, but I don't know how to make it un-bold using the same button. Do you think you could help me, please? Thank you!!
I came across a weird problem the second time I did this. My scroll bar doesn't readjust when I add more text. I was wondering if there was some method by which I could change this. I tried looking myself, but alas it is impossible to know what the heck Oracle ever means by anything.
public class Main {
public static void main(String[] args) {
new TextEditor();
}
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
public class TextEditor extends JFrame implements ActionListener{
JTextArea textArea;
JScrollPane scrollPane;
JLabel fontLabel;
JSpinner fontSizeSpinner;
JButton fontColorButton;
JComboBox fontBox;
JMenuBar menuBar;
JMenu fileMenu;
JMenuItem openItem;
JMenuItem saveItem;
JMenuItem exitItem;
TextEditor(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Bro text Editor");
this.setSize(500, 500);
this.setLayout(new FlowLayout());
this.setLocationRelativeTo(null);
textArea = new JTextArea();
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setFont(new Font("Arial",Font.PLAIN,20));
scrollPane = new JScrollPane(textArea);
scrollPane.setPreferredSize(new Dimension(450,450));
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
fontLabel = new JLabel("Font: ");
fontSizeSpinner = new JSpinner();
fontSizeSpinner.setPreferredSize(new Dimension(50,25));
fontSizeSpinner.setValue(20);
fontSizeSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
textArea.setFont(new Font(textArea.getFont().getFamily(),Font.PLAIN,(int) fontSizeSpinner.getValue()));
}
});
fontColorButton = new JButton("Color");
fontColorButton.addActionListener(this);
String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
fontBox = new JComboBox(fonts);
fontBox.addActionListener(this);
fontBox.setSelectedItem("Arial");
// ------ menubar ------
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
openItem = new JMenuItem("Open");
saveItem = new JMenuItem("Save");
exitItem = new JMenuItem("Exit");
openItem.addActionListener(this);
saveItem.addActionListener(this);
exitItem.addActionListener(this);
fileMenu.add(openItem);
fileMenu.add(saveItem);
fileMenu.add(exitItem);
menuBar.add(fileMenu);
// ------ /menubar ------
this.setJMenuBar(menuBar);
this.add(fontLabel);
this.add(fontSizeSpinner);
this.add(fontColorButton);
this.add(fontBox);
this.add(scrollPane);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==fontColorButton) {
JColorChooser colorChooser = new JColorChooser();
Color color = colorChooser.showDialog(null, "Choose a color", Color.black);
textArea.setForeground(color);
}
if(e.getSource()==fontBox) {
textArea.setFont(new Font((String)fontBox.getSelectedItem(),Font.PLAIN,textArea.getFont().getSize()));
}
if(e.getSource()==openItem) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File("."));
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files", "txt");
fileChooser.setFileFilter(filter);
int response = fileChooser.showOpenDialog(null);
if(response == JFileChooser.APPROVE_OPTION) {
File file = new File(fileChooser.getSelectedFile().getAbsolutePath());
Scanner fileIn = null;
try {
fileIn = new Scanner(file);
if(file.isFile()) {
while(fileIn.hasNextLine()) {
String line = fileIn.nextLine()+"
";
textArea.append(line);
}
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally {
fileIn.close();
}
}
}
if(e.getSource()==saveItem) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File("."));
int response = fileChooser.showSaveDialog(null);
if(response == JFileChooser.APPROVE_OPTION) {
File file;
PrintWriter fileOut = null;
file = new File(fileChooser.getSelectedFile().getAbsolutePath());
try {
fileOut = new PrintWriter(file);
fileOut.println(textArea.getText());
}
catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally {
fileOut.close();
}
}
}
if(e.getSource()==exitItem) {
System.exit(0);
}
}
}
You forgot to post your comment at the top .
Practicing...
I think I'll need to rewatch the video.
public class Main{
public static void main(String[]args){
new TextEditor();
}
}
****************
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
public class TextEditor extends JFrame implements ActionListener{
JTextArea textArea;
JScrollPane scrollPane;
JLabel fontLabel;
JSpinner fontSizeSpinner;
JButton fontColorButton;
JComboBox fontBox;
JMenuBar menuBar;
JMenu fileMenu;
JMenuItem openItem;
JMenuItem saveItem;
JMenuItem exitItem;
TextEditor(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Text Editor App");
this.setSize(380,380);
this.setLayout(new FlowLayout());
this.setLocationRelativeTo(null);
textArea = new JTextArea();
textArea.setPreferredSize(new Dimension(250,250));
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setFont(new Font("Times New Roman", Font.PLAIN,18));
scrollPane = new JScrollPane(textArea);
scrollPane.setPreferredSize(new Dimension(420,420));
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
fontLabel = new JLabel("Font: ");
fontSizeSpinner = new JSpinner();
fontSizeSpinner.setPreferredSize(new Dimension(50,25));
fontSizeSpinner.setValue(20);
fontSizeSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e){
textArea.setFont(new Font(textArea.getFont().getFamily(),Font.PLAIN,(int)fontSizeSpinner.getValue()));
}
});
fontColorButton = new JButton("Color");
fontColorButton.addActionListener(this);
String[]fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
fontBox = new JComboBox(fonts);
fontBox.addActionListener(this);
fontBox.setSelectedItem("Times New Roman");
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
openItem = new JMenuItem("Open");
saveItem = new JMenuItem("Save");
exitItem = new JMenuItem("Exit");
openItem.addActionListener(this);
saveItem.addActionListener(this);
exitItem.addActionListener(this);
fileMenu.add(openItem);
fileMenu.add(saveItem);
fileMenu.add(exitItem);
menuBar.add(fileMenu);
this.setJMenuBar(menuBar);
this.add(fontLabel);
this.add(fontSizeSpinner);
this.add(fontColorButton);
this.add(fontBox);
this.add(scrollPane);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e){
if(e.getSource()==fontColorButton){
JColorChooser colorChooser = new JColorChooser();
Color color = colorChooser.showDialog(null, "Color Choice", Color.black);
textArea.setForeground(color);
}
if(e.getSource()==fontBox){
textArea.setFont(new Font((String)fontBox.getSelectedItem(),Font.PLAIN,textArea.getFont().getSize()));
}
if(e.getSource()==openItem){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File("."));
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files","txt");
fileChooser.setFileFilter(filter);
int response = fileChooser.showOpenDialog(null);
if(response==JFileChooser.APPROVE_OPTION){
File file = new File(fileChooser.getSelectedFile().getAbsolutePath());
Scanner fileIn = null;
try{
fileIn = new Scanner(file);
if(file.isFile()){
while(fileIn.hasNextLine()){
String line = fileIn.nextLine()+"
";
textArea.append(line);
}
}
}catch(FileNotFoundException e1){
e1.printStackTrace();
}
}
}
if(e.getSource()==saveItem){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File("."));
int response = fileChooser.showSaveDialog(null);
if(response == JFileChooser.APPROVE_OPTION){
File file;
PrintWriter fileOut;
file = new File(fileChooser.getSelectedFile().getAbsolutePath());
try{
fileOut = new PrintWriter(file);
fileOut.println(textArea.getText());
}
catch(FileNotFoundException e1){
e1.printStackTrace();
}
finally{
}
}
}
if(e.getSource()==exitItem){
System.exit(0);
}
}
}
Thank you! With every video I feel like you are good in finding sweet spot between teaching a lot but not too much at one time :)
The nuclear launch codes folder never gets old, I wonder whats in there :D
hello again my friend thank you for the Tutorial
thank you for watching
38:58 the reason this guy is the best, out of 10 different playlists, with 100 or more videos in each with every each one having a duration of 10 min or more, he isnt bored and he still leaving amazing tuturial details like this one, its like even if u wanted to find this clip of him messing around with the fontSizeSpinner that he created, u couldnt, its so deep hidden but yet ultra entertaining
What you do is pure art!
Wow. Now I see why people say it takes a lot more lines of code to do the same in java
This great for tying all the previous lessons together. Thanks for making these!
Veri nice text editor app by using java
MORE THAN 750K!!! YOU DESERVE IT BROO!!
LOOKING FORWARD FOR 1 M AND MORE!!!!!
You are doing great job for java newbie
Amazing 😍 bro 👏
Thank you for the tutorial.
"Welcome to my desktop everybody" with a tinge of embarrassment like someone touring their house and showing their not so messy room as messy.
Fucking love it lol.
no idea what you're talking about
@@turrnut 32:35
Your voice is gentle. Thanks, Bro.
I literally cannot stop watching these! All your courses are spot on!
This kind of simple program made me motivated enough to keep learning java as a beginner
Yeah. You need to do mechanical coding constantly. This helps to understand whole point and functions.
lol!!! the why are you still watching at the end got me. I couldn't stop. Great tutorial!
This is going to be the inspiration for my project, thank you
awsome
Thanks to you I'm really making progress into programming, thank you so much!
You were right! That font combo-box thing did blow my mind! ( time : 17:09 ) Thank you again.
Good Tutorial
💯💯
I recently started with java so this project it's really good to practice. Thank you!
ur god damn underrated , but you don't care about it . This is what we call a legendary god. i subed
I feel like a grown programmer))
Thanks, bro
Lovely
damn , you are exactly what i am looking for, keep going such videos thanks a lot
Love u bro keep on coming these helpful videos i subscribed u
Bro code is the absolute best. I can't believe I wasted time with other Java tutorial youtubers
Thank for the best lessons i have ever seen!!!!!!
Congratulations for reaching 2k subs!!!!
thanks! We did it Mario
Thank you sir
fantastic. thank you bro
YAYYYYYYYYYYYYYYYY!!!!!!!!!CONGRATULATIONS FOR 100K😍😍😍
Great vid.
thanks 👏
Thanks
👍
thank you every thing is good ( sound , video quality , colors , time ) ❤
great project, thanks Bro.
thanks for watching jajaceek
nice
it was really great video i got to knew about some better stuff in java thank you
Why am I not surprised you have exactly what I need
Please add more projects to this playlist.
Thank you, wonderful tutorial! I was able to follow along quite easily. I don't know if it's a project or a funny name for a tutorial or smth, but I couldn't help but laugh when noticing a folder named 'Nuclear launch codes' in your desktop.
@Bro Code i really like this tutorial u made :)
but i think u should make a "find" function,im also making a option that makes the framecolor yellow,black,or white (includes textarea)
"Why are you still watching" tho in the end XD
thanks for video its good tutorial in this theme, but i have 1 question, why u not added the txt type for saving file?
Thank you !
Let's Go Bro!
How to auto write the previous object as in this video 10:22
Please let me know.
It's copy paste.
@@2ysh650 thx
Thank you so much for this video. I want to know that did you use design patterns to build this app, if yes can you name them?
This guy is a legend
Great video, as always :)
Can you please tell me how to add bold italic and underline into the editor
Thank you bro, u hellped me a lot
Absolute fire vid
Will you ever do this again but in javafx? Have a Good one bro :)
The ending was hilarious
Thank You !!!!
Just what i needed
Lol! Oh god - Hilarious. Thanks again for a great vid. The amount of time you must put into these! Much appreciated.
There is another way to read the text in a file , which you have mentioned before in file reader .
/*
// another style
public void open() {
fileChooser = new JFileChooser() ;
fileChooser.setDialogTitle("Open file") ;
fileChooser.setCurrentDirectory(new File("./src")) ;
// filter out the files that don't have specific extension name (.txt) .
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files" , "txt") ; // (title , file extension name)
fileChooser.setFileFilter(filter) ;
// show the window for opening file .
int response = fileChooser.showSaveDialog(null) ;
// if [Open] is pressed or [file] is double clicked .
if (response == JFileChooser.APPROVE_OPTION) {
// get the absolute pathname of opened file .
File file = new File(fileChooser.getSelectedFile().getAbsolutePath()) ;;
FileReader reader ;
// if opened file is file , not folder .
if (file.isFile()) {
try {
reader = new FileReader(file) ;
// clean the textArea before you add file text on it .
textArea.setText("") ;
int data = reader.read() ;
while (data != -1) {
textArea.append(String.valueOf((char)data)) ;
data = reader.read() ;
}
// it's a good behavior to close I/O stream when not in use .
reader.close() ;
openedfileText = textArea.getText() ;
// remind user the open process has finished .
JOptionPane.showMessageDialog(null , "You have opened successfully .") ;
}
catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
*/
how to make the selected text become bigger font size not all text?
wow thx
thanks man , great video !
your code is correct but in full mode menubar not display correctly can you please do this in netbeans ide where we can design the layout first then code it for logic. rest things is good.
Hey!!
I was wondering how to make a button that bolds and un-bolds the textArea. I made it so that it will bolden it, but I don't know how to make it un-bold using the same button. Do you think you could help me, please? Thank you!!
Do you have discord server or Social media?
Why are you still watching? :D
My JSpinner is not working can you please help
YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEET!!!!!
my scroll bar isn't scrolling down its only fitting to the size how do I fix this
kemo baba kazanacak
kazanamadı beyler...
i love you bro
Haha why are you still watching . Really good tutorial !
You saved my life bro
TYSM
Hey Bro, how to create editor without TextArea element, only need drawString() from paintComponent() in JFrame?
Does the code work on netbeans?
I came across a weird problem the second time I did this. My scroll bar doesn't readjust when I add more text. I was wondering if there was some method by which I could change this. I tried looking myself, but alas it is impossible to know what the heck Oracle ever means by anything.
Update. It's because I gave both the label and the scroll panel dimensions. 😅
textArea.setText("Your videos are the best");
5:14 "Press F" 😭
:D
thanks bro!
you should've added Dark Mode
Thanks mate !!
Thanks a lot! Any idea how to add option "new" to open blank a new file?
I used textArea.setText(""); to clear the text but there might be a better way.
@@jett8692 Me too, but with the font chooser, size and color. Need to restart each one to youre default one.
What do I need to do, so I can export it, so I can use it from my Desktop?
But great Video!
Here's a video on that:
ua-cam.com/video/jKlyHG-zbjk/v-deo.html&ab_channel=BroCode
just beating the algo
I'm still watching 'cause the video is still going on. lol!!!!!!
Bro source code I want how may I getting source code
Oh I am we are in the middle of a pandemic so UA-cam is kind of my dojo I’m very so I don’t have an actual dojo
this is way too complicated for me as an absolute beginner............
this is a random coment
92th. Thank you, ma Bro Sensei! System.out.println(":^)");