import java.awt.Graphics;
import javax.swing.JApplet;
public class Exercise23_7 extends JApplet
{
// method paint to paint a checker board pattern
public void paint( Graphics g )
Im trying to create a checkerboard pattern with 2 nested for loops . I need to output asterisk characters. Im supposed o use an n int so I dont know if im limited to that 1 int. Im only getting 1 line of asterisk.
* * * * * * * * * * * * * * * * * * * * package checkerboard; public class Checkerboard { public static void main(String[] args) { for (int row = 1; row < 6; row++){ System.out.print("* "); for (int col = 6; col < col; col++) {
I'm doing a project in which I must display prices of computer accessories in a Scroll Pane viewer. The if statements are all checkboxes. I am completely lost with how to print to the viewer if a checkbox is selected. Furthermore, I am also lost with how to add up all of the checkboxes.
private void USBCheckActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: double area = 0; double computerprice = 500.0; if (printerCheck.isSelected()){ double printer = 100.0;
So I'm trying to make an applet that displays images of playing cards. The applet should load a deck of 52 playing card images (the folder is called "images"). The applet should shuffle the deck (using a random number generator) and display the first 10 cards of the shuffled deck. I then have to display the cards in two rows of five cards each.
With this code I have about 100 errors and I'm not sure what I'm doing wrong:
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 my CheckerboardViewer done, my component is what I need finishing. My final product needs to be a checkerboard with alternating red and grey squares but the background is already grey. My code for the Viewer is:
import javax.swing.JFrame; public class CheckerBoardViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 400); frame.setTitle("CheckerBoardViewer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); CheckerBoardComponent component = new CheckerBoardComponent(); frame.add(component); frame.setVisible(true); } }
Anyway I am creating a game for my A2 coursework, most commonly known as Checkers. I have completed my code and everything works as I had planned except that the CheckerBoard itself as well as the checkerpieces do not appear to be showing.
The section of were my board should be present is just a black space. Although my board does not appear to be displaying, all of the actions I perform on it such as clicking certain section produces the planned response, and although I've checked through my code I cannot work out what I've done wrong.
CheckerBoard content = new CheckerBoard(); // Sets the CheckerBoard values into the content to be used in the next line application.setContentPane(content); // Container holds the values together, Content pane of the CheckerBoard application.pack(); // Use preferred size of content to set size of application. Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); application.setLocation( (screensize.width - application.getWidth())/2, (screensize.height - application.getHeight())/2 );
[Code] ....
I have noticed is that within the BoardComplete(), if you change the setBackground(Color.BLACK) to WHITE, it will change the colour of the section to white, but the checkboard is still unshown.
I've made my loop, but I am unable to get more then a 1 1 1 checkerboard properly. I am stuck on how to divide the filler characters to make the proper square size. As of now they are all one lined.
import java.util.*; public class Checker{ public static void main(String[] args) { int col, row, size; char filler; System.out.println("Please enter 3 numbers and a character."); //output
*initiating theGrid[][]* public Zhang() { con.setLayout(new FlowLayout()); for (int xDimension = 0; xDimension<theGrid.length; xDimension++)
[Code] ....
All I'm getting as a blank screen and I've searched for what to put into object oriented code to make the image show up how to program using 2d arrays. I don't get any error messages (which is good I suppose) but how to make the image show up because I have stuff under the graphics and draw methods, did I do something wrong where initializing the array?
I need to make a program that does stripes, checkerboard, and double diagonal. I can not get the stripes to work?
import java.util.Scanner; public class AsciiArt { public static void main(String[] args){ int pattern; Scanner input=new Scanner(System.in); System.out.println("Choose one of the following patterns by pressing the corresponding number"); System.out.println("1) Stripes");
I am able to get Cpu speed using my GetProcessorSpeed method and It returns this output 1796. How can apply this pattern "#.##". I am trying something like this.
Format formatter=new DecimalFormat("#.##"); formatter.format(MainClass.GetProcessorSpeed()); label2.setText(formatter.toString());
I am in an intro programming class and we got assigned a problem for creating a super class with about a dozen sub classes for generating a random word(via WordGetter class) and then comparing that word to a variety of different patterns(like: does the word contain "re"). We were given the super class which looks like this...
public class Pattern { public boolean matches(String text) { return true; } public String toString() { return "(TRUE)";
[code]...
and from this class, we have to write subclasses that override those three methods. I am struggling to understand inheritance and I am not really sure where to even start. Here is the instructions for the first sub class we need to write...
"CONTAINS" SUBCLASS Constructor: The constructor accepts a String named ‘letters’.
Matches: This pattern matches any text that contains at least one occurrence of each ‘letter’. toString: produces the text “(CONTAINS <LETTERS>)” where <LETTERS> is the ‘letters’ string. getLetters(): this method must return letters. equals(Object): careful on this one. Two Contains are equal if they have the same letters (order is not relevant). (Example):
Pattern p = new Contains(“re”); boolean f1 = p.matches(“renew”); // f1 is true boolean f2 = p.matches(“zoo”); // f2 is false String s = p.toString(); // s is “(CONTAINS re)” boolean f3 = p.equals(new Contains(“er”)); // f3 is true.. really..
I'm having a hard time implementing a simple composition example in Java:
Java Code:
public class CompositionPattern { public static void main(String[] args) { Udp udp = new Udp(); Imap imap = new Imap(); udp.startService(); imap.startService();
[Code] ....
The above won't compile. It says "The method supportsMe() is undefined for the type Object". I understand that I stored parent as an Object. But in reality it is not simply Object, but a Udp object or Imap object. The point is to make Responder generic. I don't want to have to cast the Object to Udp or Imap. Any solutions so I can keep this generic?
I need selecting which design pattern to use in my case.
I am creating a list of objects "items" to be presented in a list for the user to choose from, all objects have a title and a check box. Some objects have additional textbox for user input, some objects have additional image for illustration, and some objects have additional textbox and image as well.
I read and saw online videos but not sure if my selection "Factory Design Pattern" is the best match.
Model View Controller design pattern I completely understand then I was told about the observer controller pattern. After reading and reading I and watching video clips on youtube explaining it I have a question:
Isn't the actionListener the observer so to speak. It is firing whatever action it is told to do and dynamically updates the program to.
Example, I have a JButtons and a JTextArea. I press the button and it gives the current stock price of some stock, I press it again it refreshes. Sounds like an observer to me... Am i on the right track here?
The program I'm working on is supposed to read input from a file and using recursion, print the pattern of asterisks for each value until the value is either < 0 or > 25.For example, if the value was 4, the pattern would look like this
* * * * * * * * * * * * * * * *
The values are stored in a file entitled prog3.dat which looks like this
4 3 15 26 0
I've never used recursion before and haven't been able to find anything showing how it would work with this particular type of problem.Here is what I've been able to come up with so far, but I'm having problems still which I will show following the code.
import java.util.Scanner; import java.io.*; public class Program3 { public static void main(String[] args) throws Exception { int num = 0; java.io.File file = new java.io.File("../instr/prog3.dat"); Scanner fin = new Scanner(file);
[code]...
It appears to be reading the file correctly, but is only printing the top half of the pattern. Also, like I said, I'm not very familiar with recursion, so am not sure if this is actually recursion?
The program I'm working on is supposed to read input from a file and using recursion, print the pattern of asterisks for each value until the value is either < 0 or > 25. For example, if the value was 4, the pattern would look like this
* * * * * * * * * * * * * * * *
The values are stored in a file entitled prog3.dat which looks like this
4 3 15 26 0
I've never used recursion before and haven't been able to find anything showing how it would work with this particular type of problem. Here is what I've been able to come up with so far, but I'm having problems still which I will show following the code.
import java.util.Scanner; import java.io.*; public class Program3 { public static void main(String[] args) throws Exception { int num = 0; java.io.File file = new java.io.File("../instr/prog3.dat"); Scanner fin = new Scanner(file);
[Code] ....
Output:
Please enter an integer * * * * * * * * * * Please enter an integer * * * * * * Please enter an integer
As you can see, I don't know how to make it print the pattern like in the example and am honestly not even sure if this is recursion since I've never actually worked with recursion before.
I have a string "We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle" I need to replace the numbers based on the below condition.
if more then 5, replace with many if less then 5, replace with a few if it is 1, replace with "only one"
below is my code, I am missing the equating part to replace the numbers
private static String REGEX="(d+)"; private static String INPUT="We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle"; //String pattern= "(.*)(d+)(.*)"; private static String REPLACE = "replace with many"; public static void main(String[] args) { // Create a Pattern object