Append to a Text File - Java GUI Application

Publié le: 26 juillet 2020
sur la chaîne: Professor Saad
3,177
32

#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


Sur cette page du site, vous pouvez voir la vidéo en ligne Append to a Text File - Java GUI Application durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Professor Saad 26 juillet 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 3,177 fois et il a aimé 32 téléspectateurs. Bon visionnage!