Results 1 to 2 of 2
- 11-09-2011, 04:20 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 11
- Rep Power
- 0
help with buttons and outputting to a file
whenever i press the button, the file is created, but it will not have any text in it and i dont know how to fix this
anyone help?
heres the code:
(it may be hard to read the cod
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.FlowLayout;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.*;
public class ListPage extends JFrame
{
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
ListPage frame = new ListPage();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ListPage()
{
setVisible(true);
setTitle("List");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 874, 766);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
JTextArea list = new JTextArea();
list.setRows(40);
list.setColumns(77);
contentPane.add(list);
JScrollPane scroll= new JScrollPane(list,ScrollPaneConstants.VERTICAL_SCRO LLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCR OLLBAR_AS_NEEDED);
contentPane.add(scroll);
JButton add = new JButton("Add");
add.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
try
{
FileWriter fw = new FileWriter("C:\\Users\\Owner\\Documents\\Output.tx t");
PrintWriter output = new PrintWriter(fw);
output.print("HI");
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
contentPane.add(add);
}
}
- 11-09-2011, 04:21 AM #2
Similar Threads
-
looping through vectors and outputting to JTextArea
By danborgir in forum New To JavaReplies: 3Last Post: 04-25-2011, 08:23 PM -
outputting different letters in different colours
By Sarah24 in forum Java AppletsReplies: 4Last Post: 03-02-2011, 02:32 PM -
Help With Outputting Data To A File
By Prodigial Mouse in forum New To JavaReplies: 14Last Post: 01-24-2011, 08:01 PM -
Outputting a * triangle
By blackbeltsas in forum New To JavaReplies: 1Last Post: 10-17-2010, 11:39 AM -
Searching a string from a text file using Swing Buttons
By pradeep1_mca@yahoo.com in forum AWT / SwingReplies: 2Last Post: 09-15-2008, 09:50 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks