#JavaGUIApplication #AppendToaTextFile #JavaTextFile
CODE:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class ImageApp extends JFrame implements ActionListener {
JLabel lblAvatarName, lblAvatarImage;
JTextField txtAvatarName;
JButton register;
public ImageApp() {
super("Image App");
ImageIcon icon = new ImageIcon("Register.png");
icon = new ImageIcon(icon.getImage().getScaledInstance(40, 40, BufferedImage.SCALE_SMOOTH));
register = new JButton(icon);
register.addActionListener(this);
lblAvatarName = new JLabel("Enter Name of Avatar: ");
lblAvatarImage = new JLabel(new ImageIcon("avatar.jpg"));
txtAvatarName = new JTextField(30);
add(lblAvatarName);
add(txtAvatarName);
add(register);
add(lblAvatarImage);
// set frame properties [set layout to flowLayout, set size, make it visible,
// close operation]
setLayout(new FlowLayout());
setIconImage(new ImageIcon("warning.png").getImage());
setVisible(true);
setSize(350, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent arg0) {
String output = txtAvatarName.getText() + "\n";
try {
Files.write(Paths.get("names.txt"),
output.getBytes(), StandardOpenOption.APPEND);
}catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new ImageApp();
}
}
------------------------------------------------------------------------------------------------------
Like, Share, And Subscribe | Professor Saad Yousuf
Watch Our All Videos On This : / professorsaad
Subscribe Our Channel : / professorsaad
Playlists: / ssby79
APPEND DATA TO A TEXT FILE - Java GUI Application
On this page of the site you can watch the video online Append to a Text File - Java GUI Application with a duration of hours minute second in good quality, which was uploaded by the user Professor Saad 26 July 2020, share the link with friends and acquaintances, this video has already been watched 3,177 times on youtube and it was liked by 32 viewers. Enjoy your viewing!