Hey Everyone!
After using Devshed (possibly the worst forum I have ever encountered) I have come here with my questions and answers about Java, Python, VB, Basic C++, HTML, Game Maker, and Uni-Gasp. So, greetings!
On to the question: I have been working on a Text editor a little bit, and hit a dead halt. I can not figure out how to import text into my program. I have what I thought would work in my code, but it just doesn't seem to work! Every time I try to compile, it gives an error: "file is not public in java.awt.filedi alog; cannot be accessed from outside package". Here is the code: - package connect4;
-
import java.awt.*;
-
import javax.swing.*;
-
import java.awt.event.*;
-
import javax.imageio.*;
-
import java.io.File;
-
import javax.swing.Popup;
-
import java.io.*;
-
import java.awt.FileDialog.*;
-
import java.io.FileWriter;
-
import java.awt.image.*;
-
import java.awt.BorderLayout;
-
public class TextEdit extends JFrame implements KeyListener, MouseListener{
-
String b;
-
JTextArea a;
-
FileDialog obj = new FileDialog(this);
-
public TextEdit() throws Exception
-
{
-
try {
-
UIManager.setLookAndFeel(
-
UIManager.getSystemLookAndFeelClassName());
-
}
-
catch(Exception q) {q.printStackTrace();}
-
// JOptionPane.showMessageDialog(null,"ad");
-
-
setResizable(true);
-
setBounds(15,15,500,500);
-
a = new JTextArea("");
-
JScrollPane b = new JScrollPane(a);
-
a.setRows(50);
-
a.addKeyListener(this);
-
a.addMouseListener(this);
-
setDefaultCloseOperation(EXIT_ON_CLOSE);
-
JMenuBar menubar = new JMenuBar();
-
setJMenuBar(menubar);
-
JMenu file = new JMenu("File");
-
JMenuItem save = new JMenuItem("Save");
-
JMenuItem link = new JMenuItem("New");
-
JMenuItem quit = new JMenuItem("Quit");
-
JMenuItem open = new JMenuItem("Open");
-
//file menu
-
save.setAccelerator(
-
KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
-
save.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
-
obj.setMode(FileDialog.SAVE);
-
String filename = "Untitled";
-
obj.show();
-
filename = obj.getDirectory()+obj.getFile();
-
setTitle(filename);
-
try {
-
BufferedWriter bw = new BufferedWriter(new PrintWriter(new File(filename + ".txt")));
-
bw.write(a.getText());
-
bw.close();
-
System.out.println(a.getText());
-
}
-
catch( Exception f) {f.printStackTrace();}
-
}
-
});
-
//Here is where the problem is:
-
open.setAccelerator(
-
KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
-
open.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
-
obj.setMode(FileDialog.LOAD);
-
String filename = "Untitled";
-
obj.show();
-
filename = obj.getDirectory()+obj.getFile();
-
setTitle(filename);
-
-
BufferedReader objBrIn = new BufferedReader(new FileReader(obj.file));
-
String strTemp;
-
String strOut = "";
-
try {
-
while ((strTemp = objBrIn.readLine()) != null) {
-
strOut += (strTemp + newline);
-
}
-
a.setText(strOut);
-
}
-
catch( Exception f) {f.printStackTrace();}
-
-
}
-
});
-
-
-
-
quit.setAccelerator(
-
KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK));
-
quit.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {System.exit(0);
-
}
-
});
-
//file menu
-
//edit menu
-
link.setAccelerator(
-
KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
-
link.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
JOptionPane optionPane = new JOptionPane("Are You SURE? \n Unsaved Data WILL be lost.", JOptionPane.QUESTION_MESSAGE,JOptionPane.YES_NO_OPTION);
-
if(optionPane!=null) {
-
a.setText("");
-
}
-
}
-
});
-
-
menubar.add(file);
-
file.add(save);
-
file.add(quit);
-
file.add(link);
-
Container c = getContentPane();
-
c.add(b);
-
setVisible(true);
-
-
}
-
public void keyPressed(KeyEvent e) {
-
}
-
public void keyReleased(KeyEvent e) {}
-
public void keyTyped(KeyEvent e) {}
-
public void mouseExited(MouseEvent e) {}
-
public void mouseEntered(MouseEvent e) {}
-
public void mousePressed(MouseEvent e) {}
-
public void mouseReleased(MouseEvent e) {}
-
public void mouseClicked(MouseEvent e) {
-
if(e.getButton() == MouseEvent.BUTTON3)
-
{
-
JPopupMenu p = new JPopupMenu();
-
-
p.add("Useless!!");
-
p.show();
-
p.setVisible(true);
-
}
-
}
-
public static void main(String[] args) throws Exception
-
{
-
new TextEdit();
-
}
-
}
-
10 1656
Why don't you make your FileDialog public on line 16 and see what happens. Remember that if you don't specify an access modifier for an atrribute, protected access is assumed.
Sorry, but I am stupid :( How do you make it public?
Sorry, but I am stupid :( How do you make it public?
prefix the declaration with the word public?
I assume you mean: - public FileDialog obj = new FileDialog(this);
I didn't work. :(
Am I doing something wrong?
I assume you mean: - public FileDialog obj = new FileDialog(this);
I didn't work. :(
Am I doing something wrong?
When you say it didn't work you mean you got the same error message?
Yep. The same error message. It didn't seem to do anything.
JosAH 11,448
Recognized Expert MVP
Yep. The same error message. It didn't seem to do anything.
You can't just stick in 'public' somewhere because someone told you so and hope
for the best. A public method must be public for a reason, i.e. it must've been designed
that way and maybe that method turns up to be part of an interface implemented by
your class.
For now your class doesn't even compile; you should read what the compiler has
told you and fix the text of your source code. Just typing in what other people suggest
you without you knowing *what* you're doing is not going to help you.
kind regards,
Jos
Thats kind of why I posted this question-because I have no idea what to do. By telling me that I did it wrong and should do it myself, you helped me in no way. I still do not know what to do to make it work.
Sorry about double post.
I tinkered with the code for a little while and got this: - open.setAccelerator(
-
KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
-
open.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
-
obj.setMode(FileDialog.LOAD);
-
String filename = "Untitled";
-
obj.show();
-
filename = obj.getDirectory()+obj.getFile();
-
setTitle(filename);
-
try {
-
BufferedReader reader = new BufferedReader (new InputStreamReader( new FileInputStream (new File (filename))));
-
String firstLine = reader.readLine ();
-
System.out.println ("The first line is: " + firstLine);
-
a.setText(firstLine);
-
}
-
catch( Exception f) {f.printStackTrace();}
-
-
-
-
}
-
});
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Amir Hardon |
last post by:
I'm new to DOM and can't figure out this thing:
I'm trying to add a row to a table with a form field in one
of it's cells, but if I'm appending the field to a form
it gets out of the table. Can some one tell me what I'm doing wrong?
it looks like this:
var tbl=document.tbl;
var frm=document.frm;
var newcell=document.createElement("TD");
|
by: surrealtrauma |
last post by:
the requirement is :
Create a class called Rational (rational.h) for performing arithmetic with
fractions. Write a program to test your class.
Use Integer variables to represent the private data of the class – the
numerator and the denominator. Provide a constructor that enables an
object of this class to be initialized when it is declared....
|
by: crjunk |
last post by:
I have 4 TextBoxes on my form that I'm trying to add together to get a
grand total. Here is the code I'm using:
<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -
function calcTotalPub()
{
var tempFed = +document.Form1.value;
var tempState = +document.Form1.value;
|
by: Stormkid |
last post by:
Hey Gang, I'm trying to figure out the best way to add two times together of
the format hh:mm:ss any suggestions would be great thanks Todd
|
by: Michelle |
last post by:
I have a div that is initially empty. Clicking on a button will add some
text boxes and other controls so the user can add additional records. In
IE
all works fine but in Netscape 7.0 when I add another "record" the values
for all previous controls within the div are wiped out. In the javascript
function where I add on to the html in the...
| |
by: The Eclectic Electric |
last post by:
I'd be very grateful if anyone could help me with this. From my limited
knowledge of Javascript I don't think it is possible, but I'll punt anyway.
I downloaded and very slightly adapted this guy's Javascript "combo box" -
http://sandy.mcarthur.org/javascript/select/select.html. It allows my users
(when I get some!) to select from a list of...
|
by: tolkienarda |
last post by:
hi all
I am working on a php driven database program for a literacy program, it will allow them to keep track of classes and students, the part i am strugling with is adding new classes, the add_class page looks like:
<body>
ADD CLASS<br>
Class Title: <input type="text" value="class_title"><br>
Class Name: <input type="text"...
|
by: Sansasoon |
last post by:
Hi there,
I am supposed to do a shop ... which I ve done so far. The only thing that I can't get working is adding up to get the result
It would be really great if someone could help me (Sorry it is in GERMAN)
ThX in advance
Sansasoon
<html>
<head>
<title>Warenkorb berechnen</title>
|
by: nomad |
last post by:
Hello Everyone:
I'm having troubles with some coding and Idon't know where it is. I have delevopled a calender where the client can add events to a day. The code worked perfect on my computer but when I transfer the info I get this error.
The server encountered an unexpected condition which prevented it from fulfilling the request.
The...
|
by: didi86 |
last post by:
Please help me to adding multiple row at a time...
// Last updated 2006-02-21
<script language="javascript">
function addRowToTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |