Use JTextarea To Display Text And Then Prompt Users To Type In Certain Words
Nov 9, 2014
So currently I am trying to use a JTextarea to display text and I then prompt users to type in certain words. I have a few problems that I have encountered. Firstly when I use setText and then if I say setText again after that it erases the previous text that was set. Ideally I want to set text once per line in my whenever a certain task is fulfilled. For example if the text says enter y/n, I want the program to go to the next line once I say y or n. Another problem of course is when I setEditable to true I can edit the whole textArea. I just want to be able to edit the line which I am currently at. Is there anything that I can use that mimics the ACM console program, or even the console down below in most IDE's where everything appears to be done line by line?
Also here is an example of what I am trying to do, along with comments:
Java Code:
console.setText("Math is good!");
console.setText("What is 2+2?: "); //using getText gets the whole line, I want
//everything checked after the colon. That is where the input will be
if(line==4){
console.setText("That is correct");
}
else {
console.setText("That is incorrect");
}
//previous text lines are overriden with new ones. I don't want that, nor do I want to be able to edit the
//whole JtextArea mh_sh_highlight_all('java');
I'm working on a simple text editor, and I'm currently saving the contents of my JTextPane in a file using an HTMLEditorKit (text is a JTextPane):
private void save() throws IOException { int returnVal = fc.showSaveDialog(window); if (returnVal == JFileChooser.APPROVE_OPTION) { StyledDocument doc = (StyledDocument)text.getDocument(); HTMLEditorKit kit = new HTMLEditorKit(); BufferedOutputStream out;
[Code] ....
The problem I'm having is that after opening a file that I saved, it does not display (if I disable text/html, it displays the entire html code, but when I re-enable it, nothing displays at all.) Am I loading it wrong, or am I setting the JTextPane's text incorrectly? Or is it, perhaps, another error that I didn't catch?
Write a menu driven program that either accepts words and their meanings, or displays the list of words in lexicographical order (i.e. as in a dictionary). When an entry is to be added to the dictionary you must first enter the word as one string, and then enter the meaning as separate string. Another requirement - from time to time words become obsolete. When this happens, such word must be removed from the dictionary.
Use the JOptionPane class to enter the information.
Use the concept of linked list to carryout this exercise. You will need at minimum the following classes:
- A WordMeaning class that hold the name of a word and its meaning. - A WordMeaningNode class that creates the node of information and its link field. - A WordList class that creates and maintain a linked list of words and their meanings. - A Dictionary class that test your classes.
For the output, the program should produce two scrollable lists:
- The current list of words and their meanings. - The list of the deleted words. You need not list the meanings, just the words.
So far, I have everything coded except for the remove method, and I am not sure how to code that. I coded the add method already, but now I don't know where to begin with the remove method in my WordList class. My classes are below.
WordMeaning Class:
public class WordMeaning { String name; String definition; WordMeaning(String t, String d) { name = t; definition = d;
So I have been working on this code for a bit now... basically just supposed to be a display for a calculator, next week in my class we are learning about how to make it do stuff. so it's supposed to just look right for now. Should look something like this actually
My first question is this, how can I get the JTextArea to display over the top like the example?
My second question is I just started getting an error that compiled before, and I haven't changed anything about this line. Here is everything.
import java.awt.*; import java.awt.font.*; import javax.swing.*; @SuppressWarnings("serial") public class CalcDisplay extends JFrame{ String[] buttonText = {
[Code]...
the output looked something like this though note this is an old screengrab from while I was working on it. I have since gotten it to color correctly and I have a jtextarea below the numbers. though I need to get it to implement above the numbers and can't figure out how to do so the other example is what it should look like, disregard the color choice.The error I was getting appeared on line 36
Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method setLayout(LayoutManager) in the type Container is not applicable for the arguments (GridLayout) The constructor GridLayout(int, int, int, int) is undefined
at CalcDisplay.addComponentsToPane(CalcDisplay.java:36) at CalcDisplay.main(CalcDisplay.java:82)
This code has worked through the whole project and I haven't changed a thing.
I have a JTextArea that the user car resize. Now, I want to check if the JTextArea is displaying all the text in order to change the border color. The JTextArea line wrap is set to true. how to do this?
Basically , I'm trying to make a program that makes the Finch follow the object. I have made two classes :
NewOption52 and FollowClass.
Class NewOption52 contains a method which determines the properties of the GUI. Class FollowClass contains a main method which calls GUI method from class NewOption52 and it also contains several methods which dictates the Finch's behavior alongside with appending text to JTextArea feed.
When I connect the Finch and run the program , a GUI should appear and inside JTextArea should have text which says ""Please Place An Object in front of Finch And Then Tap Finch to Activate!". It didn't happen when I run the program.
Class NewOption52 :
import edu.cmu.ri.createlab.terk.robot.finch.Finch; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JOptionPane; import javax.swing.*; public class NewOption52
I am making a ui in which i have a JTextfield and a JButton(run). I am reading values to JTextField from text file and on pressing Jbutton a Batch file runs. Now when i press the Jbutton the batch file runs showing number running, in place of number running, i want to display the JTextfield value. So i want in place of number running it should display JTextfield value running. How can i achieve it.
I am currently working on a project that can save text from a JTextArea and also open that same saved text. The problem I am having is that when I open the saved text file it is no longer formatted.
How the file looks before saving/closing:
public class HelloWorld{ System.out.println("Hello World!"); }
How the file looks after being saved/closed then opened:
public class HelloWorld{ System.out.println("Hello World!");}
When I save the file I'm actually saving the entire thing to a single string. When I do this the String eliminates all tabbed spacing and pushes all characters to one single line.
The only ideas I had for fixing this were to either somehow use Format in the String class or record every time user tabs and add to the String.
I need adding a textbox for users to input text onto my JFRame. Also how come the
frame.add(o);
is getting an error under the "add".
Main method class:
import javax.swing.JFrame; public class main { public static void main(String[] args) { JFrame frame = new JFrame(); bot o = new bot();
[Code] ......
Other class (this is where I want the textbox to be)
import javax.swing.JTextArea; import javax.swing.JTextField; public class bot { int x; int y; JTextField f = new JTextField(); JTextArea a = new JTextArea(30, 50); }
The program is to accept a string and display all the palindrome words(the words that are same even if they are reversed-------->mom,madam,malayalam etc.)in the string.
I need to solve this program urgently.
There are no syntax errors but after typing in the sentence,no output is displayed. This is my program....
import java.util.*; class palindrome_test { public static void main(String args[]) { Scanner in=new Scanner(System.in); System.out.println("Enter a sentence"); String usersInput=in.nextLine();
Implement an applet that display historical facts. The applet will include facts from october 28 to december 4th to test the applet.
What is the best thing to add text in my GUI - JLabel, JTextArea? I am trying to display different words on my csFacts. Once a user click button yesterday and button tomorrow?
public class Facts extends JFrame implements ActionListener{ private JButton button1,button2; private JPanel panel; private JLabel label; TextField ri = new TextField(50); private void createGUI(){ setDefaultCloseOperation(EXIT_ON_CLOSE);
I have these sample strings in a text file : goldfish, fish, dish, filter and i need to extract them out with letters : "is" and need to print them out in another text file. Currently I am able to read the contents of the file but I am not able to print the same it in the new file.
public class Demo { public static void main(String[] args) { String filename = "a.txt"; try {
I am writing a program for my college class that does the following:
Reads a text file that consists of words from a-z. The content read from the file is displayed in the JTextArea, while the user can filter the search results based on what they input. For example, if the user enter's "a" then the JTextArea is updated with all words that start with the letter "a" only. Also the user can enter a substring or the whole word and the respective result will be only the words that match the user's input.
The Problem and question I have is what would be the best way to go about filtering a file of about 27,000 words based on user input. I tried using an arraylist but the problem is it took forever to update the JTextArea, which is not good. Also I am new to using JSwing so I may not be aware of a component that would make this easier.
Here is the code:
Note: the question lies within the actionPerformed method.
I have an assignment for college that involves placing randomly chosen words from a text file into a 2-d array. I have nearly completed ithowever I am having difficulty with a list of string type.What I have done so far is below,
when I try to run an instance of the program(using BlueJ) I get an error saying there is a null pointer exception at line 35 which is wordsForGrid. add (puzzleWords.get(pos));
I am thinking that this is related to the fact that at this line in the loadWordsFromFile method List <String>words=new ArrayList<String>(); I could not create an empty list of string type, i.e List<String>words = new List<String>();
Is this correct? Or am I looking in the wrong place. The textfile I am using contains over 6000 words on a separate line for each if that makes any difference.
I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.
Here's my code:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package hexconvertor; import java.util.*; import java.io.*; public class HexConvertor extends javax.swing.JFrame {
I have wrote this class who read from text line by line and save the words in fileOnTable.. Now i don't know what to read in ReadOffer to save the words in object offers and return this.. One more question.. What JUnit test can write for this code..?
I have created an enumerated data type that represents months. In my program I have asked the user for the month. I hold the month entered by user into a string variable. From that string variable I'm trying to display the month using my enumerated data type. I know I can use if statements, but is there another simple way to do it?
import java.util.Scanner; public class demo { //Enum class called month that has constants in it representing months enum month{january,february,march,april,may,june, july,august,september, october,november, december};
I want to create a program where I need to create an object of list type such as text file will contain nos like 1,2,3,4,5 and write into text file and delete the in FIFO order i.e 1,2,3,4,5...how i can achieve to write a program? I tried bt everytime got concurrent modification exception or Array out of bound exception.
I'm working on Java-GUI implementation in Ubuntu. Used font-type in the application throughout is "Arial". At earlier stage of application it was the same font-type("Arial"). As the implementation grew the font-type has been changed automatically to another font type. It seems Serif-font type.
Now I could not able to figure out the problem; why it is so.
Note- I used HTML code also for setting font style of Dialog box messages and buttons. This is the only point which I figured out. Can it is ?
I think I need to save the file into an object but I cannot seem to figure out how. I tried to save it into a string array but that did not work either. I have been working on that section for three weeks and cannot get it to display correctly.
public class DVDList2 { private static void CreateGUI(){ File file = new File("C:UsersaprildesktopDVD.txt"); JTextField txtName, txtSeason, txtSearch, txtMain; JFrame frame = new JFrame("DVD List"); txtName = new JTextField(20);