Search Results

Search found 1552 results on 63 pages for 'homework'.

Page 18/63 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • how to run/compile java code from JTextArea at Runtime? ----urgent!!! college project

    - by Lokesh Kumar
    I have a JInternalFrame painted with a BufferedImage and contained in the JDesktopPane of a JFrame.I also have a JTextArea where i want to write some java code (function) that takes the current JInternalFrame's painted BufferedImage as an input and after doing some manipulation on this input it returns another manipulated BufferedImage that paints the JInternalFrame with new manipulated Image again!!. Manipulation java code of JTextArea:- public BufferedImage customOperation(BufferedImage CurrentInputImg) { Color colOld; Color colNew; BufferedImage manipulated=new BufferedImage(CurrentInputImg.getWidth(),CurrentInputImg.getHeight(),BufferedImage.TYPE_INT_ARGB); //make all Red pixels of current image black for(int i=0;i< CurrentInputImg.getWidth();i++) { for(int j=0;j< CurrentInputImg.getHeight(),j++) { colOld=new Color(CurrentInputImg.getRGB(i,j)); colNew=new Color(0,colOld.getGreen(),colOld.getBlue(),colOld.getAlpha()); manipulated.setRGB(i,j,colNew.getRGB()); } } return manipulated; } so,how can i run/compile this JTextArea java code at runtime and get a new manipulated image for painting on JInternalFrame???????   Here is my Main class: (This class is not actual one but i have created it for u for basic interfacing containing JTextArea,JInternalFrame,Apply Button) import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.JInternalFrame; import javax.swing.JDesktopPane; import java.awt.image.*; import javax.imageio.*; import java.io.*; import java.io.File; import java.util.*; class MyCustomOperationSystem extends JFrame **{** public JInternalFrame ImageFrame; public BufferedImage CurrenFrameImage; public MyCustomOperationSystem() **{** setTitle("My Custom Image Operations"); setSize((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(),(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()); JDesktopPane desktop=new JDesktopPane(); desktop.setPreferredSize(new Dimension((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(),(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight())); try{ CurrenFrameImage=ImageIO.read(new File("c:/Lokesh.png")); }catch(Exception exp) { System.out.println("Error in Loading Image"); } ImageFrame=new JInternalFrame("Image Frame",true,true,false,true); ImageFrame.setMinimumSize(new Dimension(CurrenFrameImage.getWidth()+10,CurrenFrameImage.getHeight()+10)); ImageFrame.getContentPane().add(CreateImagePanel()); ImageFrame.setLayer(1); ImageFrame.setLocation(100,100); ImageFrame.setVisible(true); desktop.setOpaque(true); desktop.setBackground(Color.darkGray); desktop.add(ImageFrame); this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add("Center",desktop); this.getContentPane().add("South",ControlPanel()); pack(); setVisible(true); **}** public JPanel CreateImagePanel(){ JPanel tempPanel=new JPanel(){ public void paintComponent(Graphics g) { g.drawImage(CurrenFrameImage,0,0,this); } }; tempPanel.setPreferredSize(new Dimension(CurrenFrameImage.getWidth(),CurrenFrameImage.getHeight())); return tempPanel; } public JPanel ControlPanel(){ JPanel controlPan=new JPanel(new FlowLayout(FlowLayout.LEFT)); JButton customOP=new JButton("Custom Operation"); customOP.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evnt){ JFrame CodeFrame=new JFrame("Write your Code Here"); JTextArea codeArea=new JTextArea("Your Java Code Here",100,70); JScrollPane codeScrollPan=new JScrollPane(codeArea,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); CodeFrame.add(codeScrollPan); CodeFrame.setVisible(true); } }); JButton Apply=new JButton("Apply Code"); Apply.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ // What should I do!!! Here!!!!!!!!!!!!!!! } }); controlPan.add(customOP); controlPan.add(Apply); return controlPan; } public static void main(String s[]) { new MyCustomOperationSystem(); } } Note: in above class JInternalFrame (ImageFrame) is not visible even i have declared it visible. so, ImageFrame is not visible while compiling and running above class. U have to identify this problem before running it.

    Read the article

  • F# exercise help - Beginner

    - by bobjink
    I hope you can help me with these exercises I have been stuck with. I am not in particular looking for the answers. Tips that help me solve them myself are just as good :) 1. Write a function implode : char list - string so that implode s returns the characters concatenated into a string: let implode (cArray:char list) = List.foldBack (+) 0 cArray;; Error. I am thinking that i need to cast every char to strings before I do the above. I bet however, that there is a much simpler and better solution. 2. Write a function palindrome : string - bool, so that palindrome s returns true if the string s is a palindrome let isIdentical cArray1 cArray2 = (cArray1 = cArray2);; let palinDrome (word:string) = isIdentical(word.ToCharArray(), Array.rev(word.ToCharArray()));; I get the value: val palinDrome : string - (char [] * char [] - bool), which is not what I want. 3. Write a function combinePair : int list - int list so that combinePair xs returns the list with elements from xs combined into pairs. If xs contains an odd number of elements, then the last element is thrown away: I have no idea for this one.

    Read the article

  • Bash and regex problem : check for tokens entered into a Coke vending machine

    - by Michael Mao
    Hi all: Here is a "challenge question" I've got from Linux system programming lecture. Any of the following strings will give you a Coke if you kick: L = { aaaa, aab, aba, baa, bb, aaaa"a", aaaa"b", aab"a", … ab"b"a, ba"b"a, ab"bbbbbb"a, ... } The letters shown in wrapped double quotes indicate coins that would have fallen through (but those strings are still part of the language in this example). Exercise (a bit hard) show this is the language of a regular expression And this is what I've got so far : #!/usr/bin/bash echo "A bottle of Coke costs you 40 cents" echo -e "Please enter tokens (a = 10 cents, b = 20 cents) in a sequence like 'abba' :\c" read tokens #if [ $tokens = aaaa ]||[ $tokens = aab ]||[ $tokens = bb ] #then # echo "Good! now a coke is yours!" #else echo "Thanks for your money, byebye!" if [[ $token =~ 'aaaa|aab|bb' ]] then echo "Good! now a coke is yours!" else echo "Thanks for your money, byebye!" fi Sadly it doesn't work... always outputs "Thanks for your money, byebye!" I believe something is wrong with syntax... We didn't provided with any good reference book and the only instruction from the professor was to consult "anything you find useful online" and "research the problem yourself" :( I know how could I do it in any programming language such as Java, but get it done with bash script + regex seems not "a bit hard" but in fact "too hard" for anyone with little knowledge on something advanced as "lookahead"(is this the terminology ?) I don't know if there is a way to express the following concept in the language of regex: Valid entry would consist of exactly one of the three components : aaaa, aab and bb, regardless of order, followed by an arbitrary sequence of a or b's So this is what is should be like : (a{4}Ua{2}bUb{2})(aUb)* where the content in first braces is order irrelevant. Thanks a lot in advance for any hints and/or tips :)

    Read the article

  • Printing a sideways triangle in java

    - by Will
    I'm trying to print a sideways triangle in java. If the user enters 5, the output should be: * *** ***** *** * If the user enters 6, the output should be: * *** ***** ***** *** * I've gotten it to work for the case when the user enters 5, 3, or 1 but my code seems to work for those three cases only. I was wondering if anyone could help me get my code working for more cases. Here it is: public void printArrow( int n ) { int asterisks = 1; for ( int i = 0; i <= n/2; i++ ) { for ( int j = i; j < asterisks; j++ ) { System.out.print( "*" ); } asterisks += 3; System.out.println(); } asterisks = asterisks / 2 - 2; for ( int i = 0; i < n/2; i++ ) { for ( int k = i; k < asterisks; k++ ) { System.out.print( "*" ); } if ( i == 1 ) { System.out.print( "*" ); } asterisks -= 2; System.out.println(); } }

    Read the article

  • assembly language programming (prime number)

    - by chris
    Prompt the user for a positive three digit number, then read it. Let's call it N. Divide into N all integer values from 2 to (N/2)+1 and test to see if the division was even, in which case N is instantly shown to be non-prime. Output a message printing N and saying that it is not prime. If none of those integer values divide evenly (remainder never is zero), then N is shown to be prime. Output a message printing N and saying that it is prime. Ask the user if he or she wants to test another number; if the user types "n" or "N", quit. If "y" or "Y", jump back and repeat. Comments in your code are essential. Hi. I am kinda in rush to do this.. please help me doing it. I'll be much appreciated. thank you

    Read the article

  • Proving that the distance values extracted in Dijkstra's algorithm is non-decreasing?

    - by Gail
    I'm reviewing my old algorithms notes and have come across this proof. It was from an assignment I had and I got it correct, but I feel that the proof certainly lacks. The question is to prove that the distance values taken from the priority queue in Dijkstra's algorithm is a non-decreasing sequence. My proof goes as follows: Proof by contradiction. Fist, assume that we pull a vertex from Q with d-value 'i'. Next time, we pull a vertex with d-value 'j'. When we pulled i, we have finalised our d-value and computed the shortest-path from the start vertex, s, to i. Since we have positive edge weights, it is impossible for our d-values to shrink as we add vertices to our path. If after pulling i from Q, we pull j with a smaller d-value, we may not have a shortest path to i, since we may be able to reach i through j. However, we have already computed the shortest path to i. We did not check a possible path. We no longer have a guaranteed path. Contradiction.

    Read the article

  • How do I randomly fill an array in Java?

    - by Kat
    I'm writing a program that creates a 2D array from a integer n. I then have to fill the array with values from 1 to the n*n array size and check to see if it is a magic square. The way I am doing it now fills the array in order from 1 to n*n array size. How can I make that random? My code: System.out.print("Enter an whole number: "); int n = scan.nextInt(); int [][] magic = new int [n][n]; for (int row = 0; row < magic.length; row++) { for(int col = 0; col < magic[row].length; col++) magic[row][col] = ((row * n) + 1) + col; }

    Read the article

  • Explain JAVA code

    - by MIW
    I need some help to explain the meaning from line 5 to line 9. Thanks String words = "Rain Rain go away"; String mutation1, mutation2, mutation3, mutation4; mutation1 = words.toUpperCase(); System.out.println ("** " + mutation1 + " Nursery Rhyme **"); mutation1 = words.concat ("\nCome again another day"); mutation2 = "Johnny Johnny wants to play"; mutation3 = mutation2.replace (mutation2.charAt(5), 'i'); mutation4 = mutation3.substring (7, 27); System.out.print ("\'" + mutation1 + "\n" + mutation4 + "\'\n"); 10.System.out.println ("Title length: " + words.length());

    Read the article

  • Formatting a barcode with hyphens in between - Assignment question

    - by capex
    Hi, The assignment at my first year uni computing course says my program should read a barcode number, and then display the same 13 digit barcode number separated by hyphens. For example, 9300675016902 should look like 930-067501-690-1. The restrictions say I can't use the following: No arrays No strings No functions. Any directions on this? (So far I have done this: part1 = barcode/10000000000; which gives me the first three digits, and this: part4 = barcode%10; which gives me the last digit. Thanks in advance!

    Read the article

  • Neural Network Always Produces Same/Similar Outputs for Any Input

    - by l33tnerd
    I have a problem where I am trying to create a neural network for Tic-Tac-Toe. However, for some reason, training the neural network causes it to produce nearly the same output for any given input. I did take a look at Artificial neural networks benchmark, but my network implementation is built for neurons with the same activation function for each neuron, i.e. no constant neurons. To make sure the problem wasn't just due to my choice of training set (1218 board states and moves generated by a genetic algorithm), I tried to train the network to reproduce XOR. The logistic activation function was used. Instead of using the derivative, I multiplied the error by output*(1-output) as some sources suggested that this was equivalent to using the derivative. I can put the Haskell source on HPaste, but it's a little embarrassing to look at. The network has 3 layers: the first layer has 2 inputs and 4 outputs, the second has 4 inputs and 1 output, and the third has 1 output. Increasing to 4 neurons in the second layer didn't help, and neither did increasing to 8 outputs in the first layer. I then calculated errors, network output, bias updates, and the weight updates by hand based on http://hebb.mit.edu/courses/9.641/2002/lectures/lecture04.pdf to make sure there wasn't an error in those parts of the code (there wasn't, but I will probably do it again just to make sure). Because I am using batch training, I did not multiply by x in equation (4) there. I am adding the weight change, though http://www.faqs.org/faqs/ai-faq/neural-nets/part2/section-2.html suggests to subtract it instead. The problem persisted, even in this simplified network. For example, these are the results after 500 epochs of batch training and of incremental training. Input |Target|Output (Batch) |Output(Incremental) [1.0,1.0]|[0.0] |[0.5003781562785173]|[0.5009731800870864] [1.0,0.0]|[1.0] |[0.5003740346965251]|[0.5006347214672715] [0.0,1.0]|[1.0] |[0.5003734471544522]|[0.500589332376345] [0.0,0.0]|[0.0] |[0.5003674110937019]|[0.500095157458231] Subtracting instead of adding produces the same problem, except everything is 0.99 something instead of 0.50 something. 5000 epochs produces the same result, except the batch-trained network returns exactly 0.5 for each case. (Heck, even 10,000 epochs didn't work for batch training.) Is there anything in general that could produce this behavior? Also, I looked at the intermediate errors for incremental training, and the although the inputs of the hidden/input layers varied, the error for the output neuron was always +/-0.12. For batch training, the errors were increasing, but extremely slowly and the errors were all extremely small (x10^-7). Different initial random weights and biases made no difference, either. Note that this is a school project, so hints/guides would be more helpful. Although reinventing the wheel and making my own network (in a language I don't know well!) was a horrible idea, I felt it would be more appropriate for a school project (so I know what's going on...in theory, at least. There doesn't seem to be a computer science teacher at my school). EDIT: Two layers, an input layer of 2 inputs to 8 outputs, and an output layer of 8 inputs to 1 output, produces much the same results: 0.5+/-0.2 (or so) for each training case. I'm also playing around with pyBrain, seeing if any network structure there will work. Edit 2: I am using a learning rate of 0.1. Sorry for forgetting about that. Edit 3: Pybrain's "trainUntilConvergence" doesn't get me a fully trained network, either, but 20000 epochs does, with 16 neurons in the hidden layer. 10000 epochs and 4 neurons, not so much, but close. So, in Haskell, with the input layer having 2 inputs & 2 outputs, hidden layer with 2 inputs and 8 outputs, and output layer with 8 inputs and 1 output...I get the same problem with 10000 epochs. And with 20000 epochs. Edit 4: I ran the network by hand again based on the MIT PDF above, and the values match, so the code should be correct unless I am misunderstanding those equations. Some of my source code is at http://hpaste.org/42453/neural_network__not_working; I'm working on cleaning my code somewhat and putting it in a Github (rather than a private Bitbucket) repository. All of the relevant source code is now at https://github.com/l33tnerd/hsann.

    Read the article

  • C - Malloc or calloc...and how?

    - by Pedro
    Hi...i have a txt file where the first number define the size of the array's, i know that calloc or malloc can reserve memory, but how? this code: typedef struct alpha{ int *size; char name; int tot; char line[60]; }ALPHA; fgets(line,60,fp); tot=atoi(line); size=(int*)calloc(name,sizeof(int); Imagine that in the first line of the txt is the number 10, wiht this code the size of name will be 10? like name[10]???

    Read the article

  • Intel Assembly Programming

    - by Kay
    class MyString{ char buf[100]; int len; boolean append(MyString str){ int k; if(this.len + str.len>100){ for(k=0; k<str.len; k++){ this.buf[this.len] = str.buf[k]; this.len ++; } return false; } return true; } } Does the above translate to: start: push ebp ; save calling ebp mov ebp, esp ; setup new ebp push esi ; push ebx ; mov esi, [ebp + 8] ; esi = 'this' mov ebx, [ebp + 14] ; ebx = str mov ecx, 0 ; k=0 mov edx, [esi + 200] ; edx = this.len append: cmp edx + [ebx + 200], 100 jle ret_true ; if (this.len + str.len)<= 100 then ret_true cmp ecx, edx jge ret_false ; if k >= str.len then ret_false mov [esi + edx], [ebx + 2*ecx] ; this.buf[this.len] = str.buf[k] inc edx ; this.len++ aux: inc ecx ; k++ jmp append ret_true: pop ebx ; restore ebx pop esi ; restore esi pop ebp ; restore ebp ret true ret_false: pop ebx ; restore ebx pop esi ; restore esi pop ebp ; restore ebp ret false My greatest difficulty here is figuring out what to push onto the stack and the math for pointers. NOTE: I'm not allowed to use global variables and i must assume 32-bit ints, 16-bit chars and 8-bit booleans.

    Read the article

  • Data from array to sql

    - by espentf
    I'm making a webshop for a school asignment and therfore i needed to make a shopping cart. In the shopping cart the data is storred in an array. The code for when I echo it out is <tr> <td><?php echo $row['Navn'];?></td> <td><input type="text" name="antall-<?php echo $row['id_produkt'];?>" size="5" value=" <?php echo $_SESSION['handlekurv'][$row['id_produkt']]['antall'];?>" /> </td> <td><?php echo $row['Pris'];?></td> <td><?php echo $_SESSION['handlekurv'][$row['id_produkt']]['antall']*$row['Pris'];?></td></tr> What i want is the store the data this code echoes out from the array, in a sql database. Is there anyone who can help me whith this problem?

    Read the article

  • Drawing star shapes with variable parameters

    - by owca
    Hi. I have task to write program allowing users to draw stars, which can differ in size and amount of arms. When I was dealing with basic stars I was doing it with GeneralPath and tables of points : int xPoints[] = { 55, 67, 109, 73, 83, 55, 27, 37, 1, 43 }; int yPoints[] = { 0, 36, 36, 54, 96, 72, 96, 54, 36, 36 }; Graphics2D g2d = ( Graphics2D ) g; GeneralPath star = new GeneralPath(); star.moveTo( xPoints[ 0 ], yPoints[ 0 ] ); for ( int k = 1; k < xPoints.length; k++ ) star.lineTo( xPoints[ k ], yPoints[ k ] ); star.closePath(); g2d.fill( star ); What method should I choose for drawing stars with variable inner and outer radius, as well as different amount of arms ? This is what I should obtain :

    Read the article

  • Need to make sure value is within 0-255

    - by igor
    This is probably really easy, but I'm lost on how to "make sure" it is in this range.. So basically we have class Color and many functions to implement from it. this function I need is: Effects: corrects a color value to be within 0-255 inclusive. If value is outside this range, adjusts to either 0 or 255, whichever is closer. This is what I have so far: static int correctValue(int value) { if(value<0) value=0; if(value>255) value=255; } Sorry for such a simple question ;/

    Read the article

  • Read and write struct in C

    - by Sergey
    I have a struct: typedef struct student { char fname[30]; char sname[30]; char tname[30]; Faculty fac; int course; char group[10]; int room; int bad; } Student; I read it from the file: Database * dbOpen(char *fname) { FILE *fp = fopen(fname, "rb"); List *lst, *temp; Student *std; Database *db = malloc(sizeof(*db)); if (!fp) return NULL; FileNameS = fname; std = malloc(sizeof(*std)); if (!fread(std, sizeof(*std), 1, fp)) { db->head = db->tail = NULL; return db; } lst = malloc(sizeof(*lst)); lst->s = std; lst->prev = NULL; db->head = lst; while (!feof(fp)) { fread(std, sizeof(*std), 1, fp); temp = malloc(sizeof(*temp)); temp->s = std; temp->prev = lst; lst->next = temp; lst = temp; } lst->next = NULL; db->tail = lst; fclose(fp); return db; } And I have a problem... At the last record i have a such file pointer: `fp 0x10311448 {_ptr=0x00344b90 "???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? _ _iobuf * ` And i read last record 2 times... Save file code: void * dbClose(Database *db) { FILE *fp = fopen(FileNameS, "w+b"); List *lst, *temp; lst = db->head; while(lst != NULL) { fwrite(lst->s, sizeof(*(lst->s)), 1, fp); temp = lst; lst = lst->next; free(temp); } free(db); fclose(fp); }

    Read the article

  • regular expression of 0's and 1's

    - by Lopa
    Hello all I got this question which asks me to figure out why is it foolish to write a regular expression for the language that consists of strings of 0's and 1's that are palindromes( they read the same backwards and forwards). part 2 of the question says using any formal mechanism of your choice, show how it is possible to express the language that consists of strings of 0's and 1's that are palindromes?

    Read the article

  • Counting the number of characters in a file

    - by Kat
    I'm writing a program that for one part asks for the program to print how many characters (including whitespaces) are in a file. The code I have right now though returns 0 every time though and I'm not sure why it isn't counting the characters. public int getcharCount(Scanner textFile) { int count = 0; while(textFile.hasNext()) { String line = textFile.nextLine(); for(int i=0; i < line.length(); i++) count++; } return count; }

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >