Swing/AWT/SWT :: Creating A Combination Lock That Consist Of Three Strings
Oct 23, 2014
I need to use a counter to keep track of user's input. In this class I am trying to create a combination lock that takes three strings. In the tester class the user inserts three strings and both are compared to see if users input matches correct combination. I have no errors only problem is the setPosition method. My output is always false.
public class CombinationLock {
private String first;
private String second;
private String third;
private String firstGuess;
private String secondGuess;
private String thirdGuess;
private boolean open;
private int counter;
How would I create a equals method to compare strings in a class that I'm creating. I need to create the method in my class, and then call it in a driver. How would I do this?
My code is long so I will try to explain this. I have a GUI application which gets two dates from a user via multiple combo boxes (month/day/year for each, so 6 total). The assembly and processing of these dates (including the days changing based on the month) is correct.
That said, however, when interacting with the program and changing the dates back-and-fourth on the frame, the 'days' combo boxes occasionally lock to one another. For instance, if you select 5 in one, 5 mimics in the other and this cannot be undone.
These are the last relevant bits I believe before the 'SUBMIT' button is clicked and it is all processed.
Controller ... (same set-up for the departure date)
I'm suppose to read the following code and devise a program that can break the lock.
public class InsecurePasswordLock { private char[] secret; private boolean unlocked; public InsecurePasswordLock() { // secrets are usually 30 to 50 upper case characters long // but here's a hard coded example one secret = "ASECRETTHATYOUWILLNOTGUESSTODAY".toCharArray();
[Code]....
So, I believe that I can try various password lengths until I get a return from open that !=-1. But I'm not sure how to implement this. This is what I have so far to get the length:
public char[] breakLock(InsecurePasswordLock lock) { int checkCount=1; int length=0; while(checkCount!=-1){ for(int i=0;i<=25;i++){ char[] key = new char[i]; if(InsecurePasswordLock.open(key)!=-1){ // I get a fault at this line for calling a static method length=i; checkCount=-1; } } }
I get the error:
Cannot make a static reference to the non-static method open(char[]) from the type InsecurePasswordLock..
How can I keep querying the open method to get my length??
I am having a problem finding string objects in a jTable. I use setValueAt() to write string variables into a jTable.
I can then use getValueAt() to search to find any of those strings. All works fine until I edit an entry in the table. Then I can never find that string again.
In fact, if I just click in the cell type a character, then delete that character, something changes. The contents of the cell look the same but the search for it doesn't find it.
For example if I have a string "xyz" that was written in a cell. If I set the search value, "a=xyz", and "b=getValueAt(some cell)".
Then at the compare:
if(a==b) I can hover over a and b and I see that; a = (java.lang.String) xyz
and
b = (java.lang.String) xyz
[note I am using NetBeans to do this]
after the compare, the true path is taken .
If I then click in the cell then click out and try the same compare, everything is exactly the same including what gets reported when I hover. But the false path is taken at the "if".
how can I provide a lock to a CSV file while creating the CSV file using java application and how to restrict the user to open CSV file manually instead of opening the file using java application(Swings and Hibernate). That means instead of opening the file manually the user has to use java application to open that CSV file.
I have a JTable which shows pdf files. In Addition I can check if they have errors, if it so I can generate a "report" by clicking the pdf. But the report gives me errors from all of the pdfs in the table. How can I match the error messages to the pdf which I select?
Here is one of the checking methods:
public static void testAllPagesHaveSameRotation(PDFDocument pdf) throws PDFDocumentException { if (SettingsGui.testAllPagesHaveSameRotation.isSelected()) { if (pdf.getPages() == 0) { rotationError = ""; } else { rotationError = "";
So, I have this simple program that paints a string on JPanel using g2.drawString("Hello world", 40, 120). Basically, I want to be able to keep track of many strings on the JPanel at once. I'm not sure how to do this. For example, I would want to have an ArrayList of objects that keep track of these strings.
I want to be able to click-and-drag these strings so I will need to know there locations, etc.
Right now, using g2.drawString, it only draws the string. I want something like gw.draw(myStringObject).
import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; public class tree_lock_test{ int total_instances; int thread_instances = 0; int N;
[Code] .....
this is compiled with another Peterson class which has implemeted peterson lock for two threads ...
I am having an array of strings and i want to find out whether these strings contained in the array contain a similar character or not.For example i am having following strings in the array of string:
aadafbd dsfgdfbvc sdfgyub fhjgbjhjd
my program should provide following result: 3 because i have 3 characters which are similar in all the strings of the array(f,b,d).
I wrote a program that asks the user to enter some information, does some calculations and tells them what they need to order. I know there is a way I just do not know how to do it. I would like the output from the program which is presented in text fields to be printed onto a form I made in excel when a button is pressed.
I have the following task given to me (to be solved in NetBeans) :
View the contents of the file tuinman.txt: each line has a (real) number, followed by a line text.
Write the readGardener () method that reads the file completely. Only if the number is negative, write the rest of the line. (For each input line, a new line output.)
Extra: Adjust your method so you get the text after each negative number, written "word by word", among themselves. A word can contain characters that are not "letters" are (,,. '") - ,this you may ignore.
"tuinman.txt" is dutch for "gardener.txt". This txt file is located in the same map where build,nbproject,src, etc... are located. I couldn't solve this task so i looked at the solution. It didn't work... So i tried the solution of the extra bit:
public class Methods { public void readGardener() throws FileNotFoundException {
[Code] ....
The txt file is added as an attachment to this post.
The weird thing is, the first thing the program prints is "Van" "morgen" "ijlt",... wich are words from line 19 in the txt file. All the ones before line 19 the program won't print, even if the number is negative. Even weirder, the next thing that is printed after line 19 is the NUMBER from line 20, nowhere in this code do i tell the program to print a number, and yet it does... But that's not all! From line 19 on, he just prints every single thing in the document except for the negative number, if your mind didn't explode already, it sure did now!
So in short: I need some code that prints all the lines from the txt files that start with a negative number. Only the text may be printed though, there may be no numbers in the output!
The txt file, i couldn't add it as a attachment
123 -456,12 De tuinman en de dood 184,67 was hij, Kees, de enige die het zag, want niemand lette d'r op... -845,14 -8,12452 Een Perzisch Edelman: 157,24 Dus daar gaan we dan.
My requirement: when a child is selected/clicked I want to create a grandchild (there could be from zero to say 12 grandchildren). Thus if user clicks/selects childA2:
Question one: do I need any further tree related imports to get this to work?
final Tree tree = new Tree(shell, SWT.VIRTUAL | SWT.BORDER | SWT.CHECK | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE ); tree.setHeaderVisible(true); tree.setBounds(975, 00, 375, 600);
[code]...
And it is here I've tried lots of options but it's like bleak mid winter - no new leaves What seems odd is that I can see the selected/clicked child text item.getText() but if I look at the index it is always -1. And I thought the index would let me create the leaf.
I'm having trouble setting up a test for my combination method.Here's the method (It basically finds the most amount of characters that both substrings share and combines the two using the number of shared characters as a breaking point):
public static String combination(String str1, String str2, int overlap) { assert str1 != null : "Violation of: str1 is not null"; assert str2 != null : "Violation of: str2 is not null"; assert 0 <= overlap && overlap <= str1.length() && overlap <= str2.length() && str1.regionMatches(str1.length() - overlap, str2, 0, overlap) : "" + "Violation of: OVERLAPS(str1, str2, overlap)";
I am tasked with creating several JPanels each of which has a title centered at the top. As such I have created parent panel that each panel extends. However, I am uncertain as to whether drawing the string on the panel or using a JLabel is the best solution. The panels might allow dynamic resizing...
I have a problem with slider which i want to create jlabels in a panel by sliding the slider and get the value but the jlabel doesn't show in jpanel. Below is the code :
JPanel PanelBoxes; JPanel panel; JLabel c; public static void main(String[] args){ DividePanel div = new DividePanel(); div.go();
Is it good practice to create a inner class for layered panels with lots of components? In my opinion this makes the code easier to read and a lot less clustered.
combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.
I am teaching myself AWT/Swing ... It concerns an application that creates dynamic graphics using the Graphics class. I understand that the code that creates graphics should be put in a "paintComponent" method of a (descendant of a) JPanel class. And that when you want to change something on this panel outside "paintComponent", you have to call the "repaint" method, that somehow causes "paintComponent" to be invoked.
However, I don't fully understand the explanation of the example at [URL]... . It concerns an application that moves a red square when a mouse button is clicked. The code can be found at the link, but I also repeat it below.
This code indeed works. However, I don't understand why. The explanation at the Oracle site is the following.
Because we are manually setting the clip, our moveSquare method invokes the repaint method not once, but twice. The first invocation tells Swing to repaint the area of the component where the square previously was (the inherited behavior uses the UI Delegate to fill that area with the current background color.) The second invocation paints the area of the component where the square currently is.
However, what I don't understand: when repaint is first invoked, squareX and squareY still have their old values. If the invocation of repaint simply causes an invocation of paintComponent, then paintComponent should draw a red square at (squareX, squareY). Just like the second invocation of repaint causes paintComponent to draw a red suare at the new values of (squareX, squareY). Instead, the first invocation results in the red square being wiped out by the background color.
So apparently, the first invocation of repaint does not simply cause an invocation of paintComponent. What does it do?
I can sort strings in a collection by uppercase and then lowercase though I was wondering if there is any way of doing it in reverse, sorting by lowercase then by uppercase.
I'm building a text editor. At this point, the editor should be able to read and write text and rich text. I create an instance of a RichTextEditor class that I created that extends a superclass I created (that extends JTextPane). Both my rich text and plain text classes extends the superclass I created. I use the this.read() to input my plain text from buffered reader. I think I need to use the read(fileinput stream, rtf document) method from type RTFEditorKit, but I cannot use that because it does not extend RTFEditorKit. I don't want to create a new class that extends RTFEditorKit because I need stuff from the JTextPane.
here are the classes on git... the super: TextEditorPane.java
The plaintext: TextEditorWrap.java
and the rich: RichTextEditor.java
I have fiddled with the read() method in different ways. In all cases, nothing loads. If I use the BufferedReader method, it doesn't give me an RTF, just the code for the RTF file.
How should I proceed? Do I create some sort of RTF interface and implement it?