Using a variable filename

Using a variable filename

Dear sir, my program a JFrame containes of 3 JTextFields and 2 different JButtons intend to sends data to 2 Input files. The program should work like that: when I enter a data to the JTextFields and click button1, the data should write to data1.txt file. and when enter other data and click button2, it should go to data2.txt file. Can you please help me with what to do to make each JButton performs its action with its own file.
Thank you very much.
View Answers

September 14, 2010 at 3:56 PM

Hi!!!I am providing you the logic of your program.At first you add action listeners with your buttons.Now in the method actionPerformed() you must have a mean to detect which button has been clicked(either by making the buttons global variable and using the code e.getSource()==<reference variable of the button> or by associating two distinct action commands with the two buttons and using the code e.getActionCommand().equals(<action command>)).After detecting the butoon continue with your logic for the specified button.









Related Tutorials/Questions & Answers:
Using a variable filename - Java Beginners
Using a variable filename  Dear sir, my program a JFrame containes... the buttons global variable and using the code e.getSource()== or by associating two distinct action commands with the two buttons and using the code
using variable loop
using variable loop  program to print alphabets from a-z along with ASCII codes of each alphabets in two columns using a character variable loop...can anyone help me
Advertisements
Printing Session Id Using Variable
Printing Session Id Using Variable  Hi, I am a learner in PHP language. Could any one guide me, how to print session Id using variable in PHP. Thanks
using session variable determine the no of pages viewd by the user
using session variable determine the no of pages viewd by the user  using session variable determine the no of pages viewd by the user   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http
Swap two numbers without using third variable
Swap two numbers without using third variable In this section we are going to swap two variables without using the third variable. For this, we have used... from the command prompt. Instead of using temporary variable, we have done some
How to set a variable value using velocity
How to set a variable value using velocity       This Example shows you how to set variable value using velocity. The method used in this example are described below:- 1
Printing username,email Id using session variable.
Printing User Name, Email Id and Address using session variable Using $session() function, we can print user name, email id and address of the user.  <?php session_start (); #session start $email= "[email protected]
ModuleNotFoundError: No module named 'sanitize-filename'
ModuleNotFoundError: No module named 'sanitize-filename'  Hi, My... named 'sanitize-filename' How to remove the ModuleNotFoundError: No module named 'sanitize-filename' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'wheel-filename'
ModuleNotFoundError: No module named 'wheel-filename'  Hi, My... named 'wheel-filename' How to remove the ModuleNotFoundError: No module named 'wheel-filename' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'filename-to-fontawesome'
ModuleNotFoundError: No module named 'filename-to-fontawesome'  Hi...: No module named 'filename-to-fontawesome' How to remove the ModuleNotFoundError: No module named 'filename-to-fontawesome' error? Thanks   
ModuleNotFoundError: No module named 'filename-transencoding'
ModuleNotFoundError: No module named 'filename-transencoding'  Hi...: No module named 'filename-transencoding' How to remove the ModuleNotFoundError: No module named 'filename-transencoding' error? Thanks   Hi
ModuleNotFoundError: No module named 'filename-sanitizer'
ModuleNotFoundError: No module named 'filename-sanitizer'  Hi, My... named 'filename-sanitizer' How to remove the ModuleNotFoundError: No module named 'filename-sanitizer' error? Thanks   Hi, In your
unable to display image using html tag in servlet.(image src is in a variable.....). i am using netbeans IDE. plz..........do help
unable to display image using html tag in servlet.(image src is in a variable.....). i am using netbeans IDE. plz..........do help  import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException
Local Variable and Instant Variable
Local Variable and Instant Variable  difference between Local Variable and Instant Variable   Difference between local variable and instance variable Instance variable is declared within a class but not within
Converting a Filename to a URL
Converting a Filename to a URL       A file object is used to a give a filename. Creating the File... MalformedException. After this we will convert this URL to a file object by using getFile
ModuleNotFoundError: No module named 'odoo8-addon-report-custom-filename'
ModuleNotFoundError: No module named 'odoo8-addon-report-custom-filename' ...: ModuleNotFoundError: No module named 'odoo8-addon-report-custom-filename' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-report-custom-filename
ModuleNotFoundError: No module named 'odoo9-addon-report-custom-filename'
ModuleNotFoundError: No module named 'odoo9-addon-report-custom-filename' ...: ModuleNotFoundError: No module named 'odoo9-addon-report-custom-filename' How to remove the ModuleNotFoundError: No module named 'odoo9-addon-report-custom-filename
ModuleNotFoundError: No module named 'jupyter-timestamp-filename'
ModuleNotFoundError: No module named 'jupyter-timestamp-filename'  Hi...: No module named 'jupyter-timestamp-filename' How to remove the ModuleNotFoundError: No module named 'jupyter-timestamp-filename' error? Thanks
Converting jsp variable to java variable
Converting jsp variable to java variable  Hi how to convert java script variable to java variable on same jsp page
Pointer a variable
Pointer a variable  hii, Pointer is a variable or not ?   hello,ADS_TO_REPLACE_1 Yes, a pointer is a variable
Java variable
Java variable   To what value is a variable of the String type automatically initialized
Passing variable
Passing variable  How to pass variable to HTTP object in HTMl or PHP
Application Variable
Application Variable  I have multiple JSP's that are connected to a Database specifically MSSQL, I connect to the DB using a property file containing... anyone show a simple sample code of storing the connection data in a variable so
final variable
final variable  Please give some easiest and understanding example program for final variable
environment variable
environment variable  what are the environment variable is need to run j2ee application in eclipse could you explain the details
How to get filename in JTextArea in following case?
How to get filename in JTextArea in following case?  Hi, i'm... java.awt.*; import javax.swing.*; import java.awt.event.*; class FileName extends... pane; FileName(){ setLayout(null); JTextAreaOutputDirectory=new
environment variable
environment variable  what is environment variable in java?   Environment variables are used by the Operating System to pass configuration information to applications
Determining if a Filename path is a file or a directory
Determining if a Filename path is a file or a directory       You can solve this problem very easily... or a directory in it. We are using a following methods to solve this problem.ADS
Static Variable
Static Variable  What is the basic use of introducing static variable... that a certain object/variable is resident in memory and accessed each time an instance..., it means that the static variable is shared among all instances of the class
Java get Filename without Extension
Java get Filename without Extension   ... the filename without extension. For this, the file name or the directory name... getFileNameWithoutExtension() {   String fileName="C:\\anu\\My\\Hello.txt";   File
variable for cookie.setDomain - JSP-Servlet
variable for cookie.setDomain  I want to create a variable to use inside the following statement: cookie.setDomain(".mydomain.com"); Users will be hitting different sites using the same code for all. Any suggestions would
how to assign javascript variable value to a jsp variable
how to assign javascript variable value to a jsp variable  how to assign javascript variable value to a jsp variable
javascript variable value insertion in DB
javascript variable value insertion in DB  how can I insert javascript variable value into database using php
define string variable in php
define string variable in php  how to define string variable in PHP
global variable in objective c
global variable in objective c  Declaring global variable in objective c
JavaScript display variable in alert
variable is declared by using var keyword.This variable can hold any type of value...JavaScript display variable in alert  How to display variable in alert box? I am using javascript.   <html> <head> <script
php variable functions
php variable functions  Setting a variable in a class function, where can I use that variable
static variable in php
static variable in php  How can i call a global variable as a static variable
Flex Variable Scope
Scope of the variable defines the accessibility of the variable across the application. The global variable has global access to the application and local variable is restricted to the block of code only. The variable defined outside
JSP Variable in Javascript
variable using alert box. Understand with Example ADS_TO_REPLACE_1.... This  will display the value of string variable using the alertbox on loading... JSP Variable in Javascript   
how to inherit static variable
how to inherit static variable   how to inherit static variable or methods in Java?? Please explain the entire process of inheriting the variable. Thanks in advance
php search variable
php search variable  Search variable in PHP
variable function in php
variable function in php  Can any one tell me how to write a variable function in PHP?   Go through the PHP Variable function tutorial ... PHP Variable Function
php variable scope
php variable scope  How can i access a variable from scope of another function
php variable in javascript
php variable in javascript  Access php variables in Javascipt or Jquery rather than php echo $variable
variable types in php - PHP
variable types in php  Do i need to explicitly specify the variable type in PHP
variable function in php
variable function in php  Can any one tell me how to write a variable function in PHP
STATIC VARIABLE DECLARATION
STATIC VARIABLE DECLARATION  why cannot the static variable declare inside the method
variable declaration in c and c++
variable declaration in c and c++  Comparison and an example of variable declaration in C and C
What is the importance of static variable?
What is the importance of static variable?  hi, What is the importance of static variable? thanks

Ads