Search Results

Search found 6094 results on 244 pages for 'double gras'.

Page 54/244 | < Previous Page | 50 51 52 53 54 55 56 57 58 59 60 61  | Next Page >

  • design a model for a system of dependent variables

    - by dbaseman
    I'm dealing with a modeling system (financial) that has dozens of variables. Some of the variables are independent, and function as inputs to the system; most of them are calculated from other variables (independent and calculated) in the system. What I'm looking for is a clean, elegant way to: define the function of each dependent variable in the system trigger a re-calculation, whenever a variable changes, of the variables that depend on it A naive way to do this would be to write a single class that implements INotifyPropertyChanged, and uses a massive case statement that lists out all the variable names x1, x2, ... xn on which others depend, and, whenever a variable xi changes, triggers a recalculation of each of that variable's dependencies. I feel that this naive approach is flawed, and that there must be a cleaner way. I started down the path of defining a CalculationManager<TModel> class, which would be used (in a simple example) something like as follows: public class Model : INotifyPropertyChanged { private CalculationManager<Model> _calculationManager = new CalculationManager<Model>(); // each setter triggers a "PropertyChanged" event public double? Height { get; set; } public double? Weight { get; set; } public double? BMI { get; set; } public Model() { _calculationManager.DefineDependency<double?>( forProperty: model => model.BMI, usingCalculation: (height, weight) => weight / Math.Pow(height, 2), withInputs: model => model.Height, model.Weight); } // INotifyPropertyChanged implementation here } I won't reproduce CalculationManager<TModel> here, but the basic idea is that it sets up a dependency map, listens for PropertyChanged events, and updates dependent properties as needed. I still feel that I'm missing something major here, and that this isn't the right approach: the (mis)use of INotifyPropertyChanged seems to me like a code smell the withInputs parameter is defined as params Expression<Func<TModel, T>>[] args, which means that the argument list of usingCalculation is not checked at compile time the argument list (weight, height) is redundantly defined in both usingCalculation and withInputs I am sure that this kind of system of dependent variables must be common in computational mathematics, physics, finance, and other fields. Does someone know of an established set of ideas that deal with what I'm grasping at here? Would this be a suitable application for a functional language like F#? Edit More context: The model currently exists in an Excel spreadsheet, and is being migrated to a C# application. It is run on-demand, and the variables can be modified by the user from the application's UI. Its purpose is to retrieve variables that the business is interested in, given current inputs from the markets, and model parameters set by the business.

    Read the article

  • why there is no power operator in java / c ++?

    - by RanZilber
    While there is such operator - ** in Python , i was wondering why java and c++ havent got one too. It is easy to make one for classes you define in C++ with operator overloading ( and i believe such thing is possible also in java) , but when talking about primitive types such as int, double and so on , you'll have to use library function like Math.power (and usaully have to cast both to double). So - why not define such operator for primitive types ?

    Read the article

  • TechEd 2010 Important Events

    If youll be attending TechEd in New Orleans in a couple of weeks, make sure the following are all on your calendar:   Party with Palermo TechEd 2010 Edition Sunday 6 June 2010 7:30-930pm Central Time RSVP and see who else is coming here.  The party takes place from 730pm to 930pm Central (Local) Time,  and includes a full meal, free swag, and prizes.  The event is being held at Jimmy Buffetts Margaritaville located at 1104 Decatur Street.   Developer Practices Session: DPR304 FAIL: Anti-Patterns and Worst Practices Monday 7 June 2010 4:30pm-545pm Central Time Room 276 Come to my session and hear about what NOT to do on your software project.  Hear my own and others war stories and lessons learned.  Youll laugh, youll cry, youll realize youre a much better developer than a lot of folks out there.  Heres the official description: Everybody likes to talk about best practices, tips, and tricks, but often it is by analyzing failures that we learn from our own and others' mistakes. In this session, Steve describes various anti-patterns and worst practices in software development that he has encountered in his own experience or learned about from other experts in the field, along with advice on recognizing and avoiding them. View DPR304 in TechEd Session Catalog >> Exhibition Hall Reception Monday 7 June 2010 545pm-9pm Immediately following my session, come meet the shows exhibitors, win prizes, and enjoy plenty of food and drink.  Always a good time.   Party: Geekfest Tuesday 8 June 8pm-11pm Central Time, Pat OBriens Lets face it, going to a technical conference is good for your career but its not a whole lot of fun. You need an outlet. You need to have fun. Cheap beer and lousy pizza (with a New Orleans twist) We are bringing back GeekFest! Join us at Pat OBriens for a night of gumbo, beer and hurricanes. There are limited invitations available, so what are you waiting for? If you are attending the TechEd 2010 conference and you are a developer, you are invited. To register pick up your "duck" ticket (and wristband) in the TechEd Technical Learning Center (TLC) at the Developer Tools & Languages (DEV) information desk. You must have wristband to get in. Tuesday, June 8th from 8pm 11pm Pat OBriens New Orleans 624 Bourbon Street New Orleans, LA 70130 Closing Party at Mardi Gras World Thursday 10 June 730pm-10pm Central Time Join us for the Closing Party and enjoy great food, beverages, and the excitement of New Orleans at Mardi Gras World. The colors, the lights, the music, the joie de vivreits all here.  Learn more >> Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • TechEd 2010 Important Events

    If youll be attending TechEd in New Orleans in a couple of weeks, make sure the following are all on your calendar:   Party with Palermo TechEd 2010 Edition Sunday 6 June 2010 7:30-930pm Central Time RSVP and see who else is coming here.  The party takes place from 730pm to 930pm Central (Local) Time,  and includes a full meal, free swag, and prizes.  The event is being held at Jimmy Buffetts Margaritaville located at 1104 Decatur Street.   Developer Practices Session: DPR304 FAIL: Anti-Patterns and Worst Practices Monday 7 June 2010 4:30pm-545pm Central Time Room 276 Come to my session and hear about what NOT to do on your software project.  Hear my own and others war stories and lessons learned.  Youll laugh, youll cry, youll realize youre a much better developer than a lot of folks out there.  Heres the official description: Everybody likes to talk about best practices, tips, and tricks, but often it is by analyzing failures that we learn from our own and others' mistakes. In this session, Steve describes various anti-patterns and worst practices in software development that he has encountered in his own experience or learned about from other experts in the field, along with advice on recognizing and avoiding them. View DPR304 in TechEd Session Catalog >> Exhibition Hall Reception Monday 7 June 2010 545pm-9pm Immediately following my session, come meet the shows exhibitors, win prizes, and enjoy plenty of food and drink.  Always a good time.   Party: Geekfest Tuesday 8 June 8pm-11pm Central Time, Pat OBriens Lets face it, going to a technical conference is good for your career but its not a whole lot of fun. You need an outlet. You need to have fun. Cheap beer and lousy pizza (with a New Orleans twist) We are bringing back GeekFest! Join us at Pat OBriens for a night of gumbo, beer and hurricanes. There are limited invitations available, so what are you waiting for? If you are attending the TechEd 2010 conference and you are a developer, you are invited. To register pick up your "duck" ticket (and wristband) in the TechEd Technical Learning Center (TLC) at the Developer Tools & Languages (DEV) information desk. You must have wristband to get in. Tuesday, June 8th from 8pm 11pm Pat OBriens New Orleans 624 Bourbon Street New Orleans, LA 70130 Closing Party at Mardi Gras World Thursday 10 June 730pm-10pm Central Time Join us for the Closing Party and enjoy great food, beverages, and the excitement of New Orleans at Mardi Gras World. The colors, the lights, the music, the joie de vivreits all here.  Learn more >> Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • Excel VBA Userform Combobox problem

    - by Marc
    I'm having difficulties with a Combobox in a userform in an Excel document. The combobox either doesn't appear in the userform, or the combobox remains blank, and when I enter any character in it, the list of items appears, but 2 or 3 times, instead of just once. When I select an item, the chosen item doesn't appear in the box. It seems as if Excel^picks one at random, and whichever item I choose from the list, it's always the same one that ends up being displayed in the box. Can anyone help me on this one? Thanks a lot!!! This is the code I used: Private Sub ComboBox1_Change() Select Case ComboBox1.Text Case "Een nieuwe start" Case "Alles heeft zijn tijd" Case "De wereld aan je voeten" Case "Een levend boek" Case "Drempels" Case "Kerstmis" Case "Confituur of choco" Case "Hoe groot is de hemel?" Case "Ongelovige Thomas" Case "Feesten" Case "Er is er één jarig!" Case "Eén van hart" Case "Ervoor gaan" Case "Groen gras" Case "RELatie" Case "Vele plaatjes" Case "Iedereen fan" Case "Schattenjacht" Case "Lichtbakens" Case "Rijke Luis" Case "Hemel op aarde" Case "Op bezoek" Case Else End Select End Sub Private Sub UserForm1_Initialize() ComboBox1.Clear ComboBox1.AddItem "Een nieuwe start" ComboBox1.AddItem "Alles heeft zijn tijd" ComboBox1.AddItem "De wereld aan je voeten" ComboBox1.AddItem "Een levend boek" ComboBox1.AddItem "Drempels" ComboBox1.AddItem "Kerstmis" ComboBox1.AddItem "Confituur of choco" ComboBox1.AddItem "Hoe groot is de hemel?" ComboBox1.AddItem "Ongelovige Thomas" ComboBox1.AddItem "Feesten" ComboBox1.AddItem "Er is er één jarig!" ComboBox1.AddItem "Eén van hart" ComboBox1.AddItem "Ervoor gaan" ComboBox1.AddItem "Groen gras" ComboBox1.AddItem "RELatie" ComboBox1.AddItem "Vele plaatjes" ComboBox1.AddItem "Iedereen fan" ComboBox1.AddItem "Schattenjacht" ComboBox1.AddItem "Lichtbakens" ComboBox1.AddItem "Rijke Luis" ComboBox1.AddItem "Hemel op aarde" ComboBox1.AddItem "Op bezoek" ComboBox1.Text = ComboBox1.List(0) End Sub

    Read the article

  • Windows XP error message: "Windows cannot find 'explorer.exe'"

    - by Meysam
    In Windows XP I can open "My Computer" and see all the hard drives. I can also see the explorer.exe process running among other processes in Task Manager. But after opening "My Computer", when I double click on one of the drives to open it, I get the following error message: Windows cannot find 'explorer.exe'. Make sure you typed the name correctly, and then try again. To search for a file, click the start button, and then click search. Although I could detect and remove several suspicious files using Malwarebytes & Microsoft Security Essentials, the problem still remains. The interesting point is that if I right click on one folder and select Open or Explore from the menu bar, I can open the folder! but if I double click on the folder, it does not open and I get the above error message. How can I fix this problem? Any advice would be appreciated! Update: I formatted the C: drive (NTFS), a deep format, and installed a fresh Windows XP on it. I am not getting this error when I double click on C drive icon anymore. But the same error appears when I double click on other drive names. Maybe I should format them too!

    Read the article

  • problem with revalidating a jframe.

    - by John Quesie
    I have this code which should take the radio button input do a little math and display a popup. which it does fine. but then it is supposed to re validate and ask the next question. when i get to the second question, the answer always comes out as the isSelected(true) value no matter which radio button you click on. SO to be clear the first time through it works fin but when the second question comes up, it just takes the default radio button every time. public class EventHandler implements ActionListener { private Main gui; public EventHandler(Main gui){ this.gui = gui; } public void actionPerformed(ActionEvent e){ String answer = ""; double val = 1; //get current answer set String [] anArr = gui.getAnswers(gui.currentStage, gui.currentQuestion); if(e.getSource() == gui.exit){ System.exit(0); } if(e.getSource() == gui.submit){ if(gui.a1.isSelected()){ answer = anArr[0]; val = gui.getScore(1); } if(gui.a2.isSelected()){ answer = anArr[1]; val = gui.getScore(2); } if(gui.a3.isSelected()){ answer = anArr[2]; val = gui.getScore(3); } if(gui.a4.isSelected()){ answer = anArr[3];; val = gui.getScore(4); } JOptionPane.showMessageDialog(null, popupMessage(answer, val), "Your Answer", 1); //compute answer here //figure out what next question is to send gui.moveOn(); gui.setQA(gui.currentStage, gui.currentQuestion); //resets gui gui.goWest(); gui.q.revalidate(); } } public String popupMessage(String ans, double val){ //displays popup after an answer has been choosen gui.computeScore(val); String text = " You Answered " + ans + " Your score is now " + gui.yourScore ; return text; } } public class Main extends JFrame { public JLabel question; public JButton exit; public JButton submit; public JRadioButton a1; public JRadioButton a2; public JRadioButton a3; public JRadioButton a4; public ButtonGroup bg; public double yourScore = 1; public int currentQuestion = 1; public String currentStage = "startup"; JPanel q; public Main(){ setTitle("Ehtics Builder"); setLocation(400,400); setLayout(new BorderLayout(5,5)); setQA("startup", 1); goNorth(); goEast(); goWest(); goSouth(); goCenter(); pack(); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void goNorth(){ } public void goWest(){ q = new JPanel(); q.setLayout(new GridLayout(0,1)); q.add(question); bg.add(a1); bg.add(a2); bg.add(a3); bg.add(a4); a1.setSelected(true); q.add(a1); q.add(a2); q.add(a3); q.add(a4); add(q, BorderLayout.WEST); System.out.println(); } public void goEast(){ } public void goSouth(){ JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.CENTER)); exit = new JButton("Exit"); submit = new JButton("Submit"); p.add(exit); p.add(submit); add(p, BorderLayout.SOUTH); EventHandler myEventHandler = new EventHandler(this); exit.addActionListener(myEventHandler); submit.addActionListener(myEventHandler); } public void goCenter(){ } public static void main(String[] args) { Main open = new Main(); } public String getQuestion(String type, int num){ //reads the questions from a file String question = ""; String filename = ""; String [] ques; num = num - 1; if(type.equals("startup")){ filename = "startup.txt"; }else if(type.equals("small")){ filename = "small.txt"; }else if(type.equals("mid")){ filename = "mid.txt"; }else if(type.equals("large")){ filename = "large.txt"; }else{ question = "error"; return question; } ques = readFile(filename); for(int i = 0;i < ques.length;i++){ if(i == num){ question = ques[i]; } } return question; } public String [] getAnswers(String type, int num){ //reads the answers from a file String filename = ""; String temp = ""; String [] group; String [] ans; num = num - 1; if(type.equals("startup")){ filename = "startupA.txt"; }else if(type.equals("small")){ filename = "smallA.txt"; }else if(type.equals("mid")){ filename = "midA.txt"; }else if(type.equals("large")){ filename = "largeA.txt"; }else{ System.out.println("Error"); } group = readFile(filename); for(int i = 0;i < group.length;i++){ if(i == num){ temp = group[i]; } } ans = temp.split("-"); return ans; } public String [] getValues(String type, int num){ //reads the answers from a file String filename = ""; String temp = ""; String [] group; String [] vals; num = num - 1; if(type.equals("startup")){ filename = "startupV.txt"; }else if(type.equals("small")){ filename = "smallV.txt"; }else if(type.equals("mid")){ filename = "midV.txt"; }else if(type.equals("large")){ filename = "largeV.txt"; }else{ System.out.println("Error"); } group = readFile(filename); for(int i = 0;i < group.length;i++){ if(i == num){ temp = group[i]; } } vals = temp.split("-"); return vals; } public String [] readFile(String filename){ //reads the contentes of a file, for getQuestions and getAnswers String text = ""; int i = -1; FileReader in = null; File f = new File(filename); try{ in = new FileReader(f); }catch(FileNotFoundException e){ System.out.println("file does not exist"); } try{ while((i = in.read()) != -1) text += ((char)i); }catch(IOException e){ System.out.println("Error reading file"); } try{ in.close(); }catch(IOException e){ System.out.println("Error reading file"); } String [] questions = text.split(":"); return questions; } public void computeScore(double val){ //calculates you score times the value of your answer yourScore = val * yourScore; } public double getScore(int aNum){ //gets the score of an answer, stage and q number is already set in the class aNum = aNum - 1; double val = 0; double [] valArr = new double[4]; for(int i = 0;i < getValues(currentStage, currentQuestion).length;i++){ val = Double.parseDouble(getValues(currentStage, currentQuestion)[i]); valArr[i] = val; } if(aNum == 0){ val = valArr[0]; } if(aNum == 1){ val = valArr[1]; } if(aNum == 2){ val = valArr[2]; } if(aNum == 3){ val = valArr[3]; } // use current stage and questiion and trhe aNum to get the value for that answer return val; } public void nextQuestion(int num){ //sets next question to use currentQuestion = num; } public void nextStage(String sta){ // sets next stage to use currentStage = sta; } public void moveOn(){ // uses the score and current question and stage to determine wher to go next and what stage to use next nextQuestion(2); nextStage("startup"); } public void setQA(String level, int num){ String [] arr = getAnswers(level, num); question = new JLabel(getQuestion(level, num)); bg = new ButtonGroup(); a1 = new JRadioButton(arr[0]); a2 = new JRadioButton(arr[1]); a3 = new JRadioButton(arr[2]); a4 = new JRadioButton(arr[3]); } }

    Read the article

  • Modifying and Manipulating a interactive bezier curve

    - by rachel
    This is a homework question and I'm having a lot of trouble with it - I've managed to do some of it but still cant finish it - can i Please get some help. Q1. Bezier Curves The following example allows you to interactively control a bezier curve by dragging the control points Cubic.java Replace the call to draw the cubic shape (big.draw(cubic)), by your own function to draw a bezier by the recursive split method. Finally, add the ability to create a longer Bezier curve by adding more control points to create a second curve. Cubic.java import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.applet.Applet; import java.awt.geom.*; import java.awt.image.BufferedImage; public class Cubic extends JApplet{ static protected JLabel label; CubicPanel cubicPanel; public void init(){ //Initialize the layout. getContentPane().setLayout(new BorderLayout()); cubicPanel = new CubicPanel(); cubicPanel.setBackground(Color.white); getContentPane().add(cubicPanel); label = new JLabel("Drag the points to adjust the curve."); getContentPane().add("South", label); } public static void main(String s[]) { JFrame f = new JFrame("Cubic"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); JApplet applet = new Cubic(); f.getContentPane().add(applet, BorderLayout.CENTER); applet.init(); f.setSize(new Dimension(350,250)); f.setVisible(true); } } class CubicPanel extends JPanel implements MouseListener, MouseMotionListener{ BufferedImage bi; Graphics2D big; int x, y; Rectangle area, startpt, endpt, onept, twopt, rect; CubicCurve2D.Double cubic = new CubicCurve2D.Double(); Point2D.Double start, end, one, two, point; boolean firstTime = true; boolean pressOut = false; public CubicPanel(){ setBackground(Color.white); addMouseMotionListener(this); addMouseListener(this); start = new Point2D.Double(); one = new Point2D.Double(); two = new Point2D.Double(); end = new Point2D.Double(); cubic.setCurve(start, one, two, end); startpt = new Rectangle(0, 0, 8, 8); endpt = new Rectangle(0, 0, 8, 8); onept = new Rectangle(0, 0, 8, 8); twopt = new Rectangle(0, 0, 8, 8); } public void mousePressed(MouseEvent e){ x = e.getX(); y = e.getY(); if(startpt.contains(x, y)){ rect = startpt; point = start; x = startpt.x - e.getX(); y = startpt.y - e.getY(); updateLocation(e); } else if(endpt.contains(x, y)){ rect = endpt; point = end; x = endpt.x - e.getX(); y = endpt.y - e.getY(); updateLocation(e); } else if(onept.contains(x, y)){ rect = onept; point = one; x = onept.x - e.getX(); y = onept.y - e.getY(); updateLocation(e); } else if(twopt.contains(x, y)){ rect = twopt; point = two; x = twopt.x - e.getX(); y = twopt.y - e.getY(); updateLocation(e); } else { pressOut = true; } } public void mouseDragged(MouseEvent e){ if(!pressOut) { updateLocation(e); } } public void mouseReleased(MouseEvent e){ if(startpt.contains(e.getX(), e.getY())){ rect = startpt; point = start; updateLocation(e); } else if(endpt.contains(e.getX(), e.getY())){ rect = endpt; point = end; updateLocation(e); } else if(onept.contains(e.getX(), e.getY())){ rect = onept; point = one; updateLocation(e); } else if(twopt.contains(e.getX(), e.getY())){ rect = twopt; point = two; updateLocation(e); } else { pressOut = false; } } public void mouseMoved(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void updateLocation(MouseEvent e){ rect.setLocation((x + e.getX())-4, (y + e.getY())-4); point.setLocation(x + e.getX(), y + e.getY()); checkPoint(); cubic.setCurve(start, one, two, end); repaint(); } public void paintComponent(Graphics g){ super.paintComponent(g); update(g); } public void update(Graphics g){ Graphics2D g2 = (Graphics2D)g; Dimension dim = getSize(); int w = dim.width; int h = dim.height; if(firstTime){ // Create the offsecren graphics to render to bi = (BufferedImage)createImage(w, h); big = bi.createGraphics(); // Get some initial positions for the control points start.setLocation(w/2-50, h/2); end.setLocation(w/2+50, h/2); one.setLocation((int)(start.x)+25, (int)(start.y)-25); two.setLocation((int)(end.x)-25, (int)(end.y)+25); // Set the initial positions of the squares that are // drawn at the control points startpt.setLocation((int)((start.x)-4), (int)((start.y)-4)); endpt.setLocation((int)((end.x)-4), (int)((end.y)-4)); onept.setLocation((int)((one.x)-4), (int)((one.y)-4)); twopt.setLocation((int)((two.x)-4), (int)((two.y)-4)); // Initialise the CubicCurve2D cubic.setCurve(start, one, two, end); // Set some defaults for Java2D big.setColor(Color.black); big.setStroke(new BasicStroke(5.0f)); big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); area = new Rectangle(dim); firstTime = false; } // Clears the rectangle that was previously drawn. big.setColor(Color.white); big.clearRect(0, 0, area.width, area.height); // Set the colour for the bezier big.setPaint(Color.black); // Replace the following line by your own function to // draw the bezier specified by start, one, two, end big.draw(cubic); // Draw the control points big.setPaint(Color.red); big.fill(startpt); big.setPaint(Color.magenta); big.fill(endpt); big.setPaint(Color.blue); big.fill(onept); big.setPaint(new Color(0, 200, 0)); big.fill(twopt); // Draws the buffered image to the screen. g2.drawImage(bi, 0, 0, this); } /* Checks if the rectangle is contained within the applet * window. If the rectangle is not contained withing the * applet window, it is redrawn so that it is adjacent to the * edge of the window and just inside the window. */ void checkPoint(){ if (area == null) { return; } if((area.contains(rect)) && (area.contains(point))){ return; } int new_x = rect.x; int new_y = rect.y; double new_px = point.x; double new_py = point.y; if((rect.x+rect.width)>area.getWidth()){ new_x = (int)area.getWidth()-(rect.width-1); } if(point.x > area.getWidth()){ new_px = (int)area.getWidth()-1; } if(rect.x < 0){ new_x = -1; } if(point.x < 0){ new_px = -1; } if((rect.y+rect.width)>area.getHeight()){ new_y = (int)area.getHeight()-(rect.height-1); } if(point.y > area.getHeight()){ new_py = (int)area.getHeight()-1; } if(rect.y < 0){ new_y = -1; } if(point.y < 0){ new_py = -1; } rect.setLocation(new_x, new_y); point.setLocation(new_px, new_py); } }

    Read the article

  • Using Subjects to Deploy Queries Dynamically

    - by Roman Schindlauer
    In the previous blog posting, we showed how to construct and deploy query fragments to a StreamInsight server, and how to re-use them later. In today’s posting we’ll integrate this pattern into a method of dynamically composing a new query with an existing one. The construct that enables this scenario in StreamInsight V2.1 is a Subject. A Subject lets me create a junction element in an existing query that I can tap into while the query is running. To set this up as an end-to-end example, let’s first define a stream simulator as our data source: var generator = myApp.DefineObservable(     (TimeSpan t) => Observable.Interval(t).Select(_ => new SourcePayload())); This ‘generator’ produces a new instance of SourcePayload with a period of t (system time) as an IObservable. SourcePayload happens to have a property of type double as its payload data. Let’s also define a sink for our example—an IObserver of double values that writes to the console: var console = myApp.DefineObserver(     (string label) => Observer.Create<double>(e => Console.WriteLine("{0}: {1}", label, e)))     .Deploy("ConsoleSink"); The observer takes a string as parameter which is used as a label on the console, so that we can distinguish the output of different sink instances. Note that we also deploy this observer, so that we can retrieve it later from the server from a different process. Remember how we defined the aggregation as an IQStreamable function in the previous article? We will use that as well: var avg = myApp     .DefineStreamable((IQStreamable<SourcePayload> s, TimeSpan w) =>         from win in s.TumblingWindow(w)         select win.Avg(e => e.Value))     .Deploy("AverageQuery"); Then we define the Subject, which acts as an observable sequence as well as an observer. Thus, we can feed a single source into the Subject and have multiple consumers—that can come and go at runtime—on the other side: var subject = myApp.CreateSubject("Subject", () => new Subject<SourcePayload>()); Subject are always deployed automatically. Their name is used to retrieve them from a (potentially) different process (see below). Note that the Subject as we defined it here doesn’t know anything about temporal streams. It is merely a sequence of SourcePayloads, without any notion of StreamInsight point events or CTIs. So in order to compose a temporal query on top of the Subject, we need to 'promote' the sequence of SourcePayloads into an IQStreamable of point events, including CTIs: var stream = subject.ToPointStreamable(     e => PointEvent.CreateInsert<SourcePayload>(e.Timestamp, e),     AdvanceTimeSettings.StrictlyIncreasingStartTime); In a later posting we will show how to use Subjects that have more awareness of time and can be used as a junction between QStreamables instead of IQbservables. Having turned the Subject into a temporal stream, we can now define the aggregate on this stream. We will use the IQStreamable entity avg that we defined above: var longAverages = avg(stream, TimeSpan.FromSeconds(5)); In order to run the query, we need to bind it to a sink, and bind the subject to the source: var standardQuery = longAverages     .Bind(console("5sec average"))     .With(generator(TimeSpan.FromMilliseconds(300)).Bind(subject)); Lastly, we start the process: standardQuery.Run("StandardProcess"); Now we have a simple query running end-to-end, producing results. What follows next is the crucial part of tapping into the Subject and adding another query that runs in parallel, using the same query definition (the “AverageQuery”) but with a different window length. We are assuming that we connected to the same StreamInsight server from a different process or even client, and thus have to retrieve the previously deployed entities through their names: // simulate the addition of a 'fast' query from a separate server connection, // by retrieving the aggregation query fragment // (instead of simply using the 'avg' object) var averageQuery = myApp     .GetStreamable<IQStreamable<SourcePayload>, TimeSpan, double>("AverageQuery"); // retrieve the input sequence as a subject var inputSequence = myApp     .GetSubject<SourcePayload, SourcePayload>("Subject"); // retrieve the registered sink var sink = myApp.GetObserver<string, double>("ConsoleSink"); // turn the sequence into a temporal stream var stream2 = inputSequence.ToPointStreamable(     e => PointEvent.CreateInsert<SourcePayload>(e.Timestamp, e),     AdvanceTimeSettings.StrictlyIncreasingStartTime); // apply the query, now with a different window length var shortAverages = averageQuery(stream2, TimeSpan.FromSeconds(1)); // bind new sink to query and run it var fastQuery = shortAverages     .Bind(sink("1sec average"))     .Run("FastProcess"); The attached solution demonstrates the sample end-to-end. Regards, The StreamInsight Team

    Read the article

  • Generic Aggregation of C++ Objects by Attribute When Attribute Name is Unknown at Runtime

    - by stretch
    I'm currently implementing a system with a number of class's representing objects such as client, business, product etc. Standard business logic. As one might expect each class has a number of standard attributes. I have a long list of essentially identical requirements such as: the ability to retrieve all business' whose industry is manufacturing. the ability to retrieve all clients based in London Class business has attribute sector and client has attribute location. Clearly this a relational problem and in pseudo SQL would look something like: SELECT ALL business in business' WHERE sector == manufacturing Unfortunately plugging into a DB is not an option. What I want to do is have a single generic aggregation function whose signature would take the form: vector<generic> genericAggregation(class, attribute, value); Where class is the class of object I want to aggregate, attribute and value being the class attribute and value of interest. In my example I've put vector as return type, but this wouldn't work. Probably better to declare a vector of relevant class type and pass it as an argument. But this isn't the main problem. How can I accept arguments in string form for class, attribute and value and then map these in a generic object aggregation function? Since it's rude not to post code, below is a dummy program which creates a bunch of objects of imaginatively named classes. Included is a specific aggregation function which returns a vector of B objects whose A object is equal to an id specified at the command line e.g. .. $ ./aggregations 5 which returns all B's whose A objects 'i' attribute is equal to 5. See below: #include <iostream> #include <cstring> #include <sstream> #include <vector> using namespace std; //First imaginativly names dummy class class A { private: int i; double d; string s; public: A(){} A(int i, double d, string s) { this->i = i; this->d = d; this->s = s; } ~A(){} int getInt() {return i;} double getDouble() {return d;} string getString() {return s;} }; //second imaginativly named dummy class class B { private: int i; double d; string s; A *a; public: B(int i, double d, string s, A *a) { this->i = i; this->d = d; this->s = s; this->a = a; } ~B(){} int getInt() {return i;} double getDouble() {return d;} string getString() {return s;} A* getA() {return a;} }; //Containers for dummy class objects vector<A> a_vec (10); vector<B> b_vec;//100 //Util function, not important.. string int2string(int number) { stringstream ss; ss << number; return ss.str(); } //Example function that returns a new vector containing on B objects //whose A object i attribute is equal to 'id' vector<B> getBbyA(int id) { vector<B> result; for(int i = 0; i < b_vec.size(); i++) { if(b_vec.at(i).getA()->getInt() == id) { result.push_back(b_vec.at(i)); } } return result; } int main(int argc, char** argv) { //Create some A's and B's, each B has an A... //Each of the 10 A's are associated with 10 B's. for(int i = 0; i < 10; ++i) { A a(i, (double)i, int2string(i)); a_vec.at(i) = a; for(int j = 0; j < 10; j++) { B b((i * 10) + j, (double)j, int2string(i), &a_vec.at(i)); b_vec.push_back(b); } } //Got some objects so lets do some aggregation //Call example aggregation function to return all B objects //whose A object has i attribute equal to argv[1] vector<B> result = getBbyA(atoi(argv[1])); //If some B's were found print them, else don't... if(result.size() != 0) { for(int i = 0; i < result.size(); i++) { cout << result.at(i).getInt() << " " << result.at(i).getA()->getInt() << endl; } } else { cout << "No B's had A's with attribute i equal to " << argv[1] << endl; } return 0; } Compile with: g++ -o aggregations aggregations.cpp If you wish :) Instead of implementing a separate aggregation function (i.e. getBbyA() in the example) I'd like to have a single generic aggregation function which accounts for all possible class attribute pairs such that all aggregation requirements are met.. and in the event additional attributes are added later, or additional aggregation requirements, these will automatically be accounted for. So there's a few issues here but the main one I'm seeking insight into is how to map a runtime argument to a class attribute. I hope I've provided enough detail to adequately describe what I'm trying to do...

    Read the article

  • Producer and Consumer Threads Hang

    - by user972425
    So this is my first foray into threads and thus far it is driving me insane. My problem seems to be some kind of synchronization error that causes my consumer thread to hang. I've looked at other code and just about everything I could find and I can't find what my error is. There also seems to be a discrepancy between the code being executed in Eclipse and via javac in the command line. Intention - Using a bounded buffer (with 1000 slots) create and consume 1,000,000 doubles. Use only notify and wait. Problem - In Eclipse the consumer thread will occasionally hang around 940,000 iterations, but other times completes. In the command line the consumer thread always hangs. Output - Eclipse - Successful Producer has produced 100000 doubles. Consumer has consumed 100000 doubles. Producer has produced 200000 doubles. Consumer has consumed 200000 doubles. Producer has produced 300000 doubles. Consumer has consumed 300000 doubles. Producer has produced 400000 doubles. Consumer has consumed 400000 doubles. Producer has produced 500000 doubles. Consumer has consumed 500000 doubles. Producer has produced 600000 doubles. Consumer has consumed 600000 doubles. Producer has produced 700000 doubles. Consumer has consumed 700000 doubles. Producer has produced 800000 doubles. Consumer has consumed 800000 doubles. Producer has produced 900000 doubles. Consumer has consumed 900000 doubles. Producer has produced 1000000 doubles. Producer has produced all items. Consumer has consumed 1000000 doubles. Consumer has consumed all items. Exitting Output - Command Line/Eclipse - Unsuccessful Producer has produced 100000 doubles. Consumer has consumed 100000 doubles. Producer has produced 200000 doubles. Consumer has consumed 200000 doubles. Producer has produced 300000 doubles. Consumer has consumed 300000 doubles. Producer has produced 400000 doubles. Consumer has consumed 400000 doubles. Producer has produced 500000 doubles. Consumer has consumed 500000 doubles. Producer has produced 600000 doubles. Consumer has consumed 600000 doubles. Producer has produced 700000 doubles. Consumer has consumed 700000 doubles. Producer has produced 800000 doubles. Consumer has consumed 800000 doubles. Producer has produced 900000 doubles. Consumer has consumed 900000 doubles. Producer has produced 1000000 doubles. Producer has produced all items. At this point it just sits and hangs. Any help you can provide about where I might have misstepped is greatly appreciated. Code - Producer thread import java.text.DecimalFormat;+ " doubles. Cumulative value of generated items= " + temp) import java.util.*; import java.io.*; public class producer implements Runnable{ private buffer produceBuff; public producer (buffer buff){ produceBuff = buff; } public void run(){ Random random = new Random(); double temp = 0, randomElem; DecimalFormat df = new DecimalFormat("#.###"); for(int i = 1; i<=1000000; i++) { randomElem = (Double.parseDouble( df.format(random.nextDouble() * 100.0))); try { produceBuff.add(randomElem); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } temp+= randomElem; if(i%100000 == 0) {produceBuff.print("Producer has produced "+ i ); } } produceBuff.print("Producer has produced all items."); } } Consumer thread import java.util.*; import java.io.*; public class consumer implements Runnable{ private buffer consumBuff; public consumer (buffer buff){ consumBuff = buff; } public void run(){ double temp = 0; for(int i = 1; i<=1000000; i++) { try { temp += consumBuff.get(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(i%100000 == 0) {consumBuff.print("Consumer has consumed "+ i ); //if(i>999000) //{System.out.println("Consuming item " + i);} } consumBuff.print("Consumer has consumed all items."); } } Buffer/Main import java.util.*; import java.io.*; public class buffer { private double buff[]; private int addPlace; private int getPlace; public buffer(){ buff = new double[1000]; addPlace = 0; getPlace = 0; } public synchronized void add(double add) throws InterruptedException{ if((addPlace+1 == getPlace) ) { try { wait(); } catch (InterruptedException e) {throw e;} } buff[addPlace] = add; addPlace = (addPlace+1)%1000; notify(); } public synchronized double get()throws InterruptedException{ if(getPlace == addPlace) { try { wait(); } catch (InterruptedException e) {throw e;} } double temp = buff[getPlace]; getPlace = (getPlace+1)%1000; notify(); return temp; } public synchronized void print(String view) { System.out.println(view); } public static void main(String args[]){ buffer buf = new buffer(); Thread produce = new Thread(new producer(buf)); Thread consume = new Thread(new consumer(buf)); produce.start(); consume.start(); try { produce.join(); consume.join(); } catch (InterruptedException e) {return;} System.out.println("Exitting"); } }

    Read the article

  • Logic error for Gauss elimination

    - by iwanttoprogram
    Logic error problem with the Gaussian Elimination code...This code was from my Numerical Methods text in 1990's. The code is typed in from the book- not producing correct output... Sample Run: SOLUTION OF SIMULTANEOUS LINEAR EQUATIONS USING GAUSSIAN ELIMINATION This program uses Gaussian Elimination to solve the system Ax = B, where A is the matrix of known coefficients, B is the vector of known constants and x is the column matrix of the unknowns. Number of equations: 3 Enter elements of matrix [A] A(1,1) = 0 A(1,2) = -6 A(1,3) = 9 A(2,1) = 7 A(2,2) = 0 A(2,3) = -5 A(3,1) = 5 A(3,2) = -8 A(3,3) = 6 Enter elements of [b] vector B(1) = -3 B(2) = 3 B(3) = -4 SOLUTION OF SIMULTANEOUS LINEAR EQUATIONS The solution is x(1) = 0.000000 x(2) = -1.#IND00 x(3) = -1.#IND00 Determinant = -1.#IND00 Press any key to continue . . . The code as copied from the text... //Modified Code from C Numerical Methods Text- June 2009 #include <stdio.h> #include <math.h> #define MAXSIZE 20 //function prototype int gauss (double a[][MAXSIZE], double b[], int n, double *det); int main(void) { double a[MAXSIZE][MAXSIZE], b[MAXSIZE], det; int i, j, n, retval; printf("\n \t SOLUTION OF SIMULTANEOUS LINEAR EQUATIONS"); printf("\n \t USING GAUSSIAN ELIMINATION \n"); printf("\n This program uses Gaussian Elimination to solve the"); printf("\n system Ax = B, where A is the matrix of known"); printf("\n coefficients, B is the vector of known constants"); printf("\n and x is the column matrix of the unknowns."); //get number of equations n = 0; while(n <= 0 || n > MAXSIZE) { printf("\n Number of equations: "); scanf ("%d", &n); } //read matrix A printf("\n Enter elements of matrix [A]\n"); for (i = 0; i < n; i++) for (j = 0; j < n; j++) { printf(" A(%d,%d) = ", i + 1, j + 1); scanf("%lf", &a[i][j]); } //read {B} vector printf("\n Enter elements of [b] vector\n"); for (i = 0; i < n; i++) { printf(" B(%d) = ", i + 1); scanf("%lf", &b[i]); } //call Gauss elimination function retval = gauss(a, b, n, &det); //print results if (retval == 0) { printf("\n\t SOLUTION OF SIMULTANEOUS LINEAR EQUATIONS\n"); printf("\n\t The solution is"); for (i = 0; i < n; i++) printf("\n \t x(%d) = %lf", i + 1, b[i]); printf("\n \t Determinant = %lf \n", det); } else printf("\n \t SINGULAR MATRIX \n"); return 0; } /* Solves the system of equations [A]{x} = {B} using */ /* the Gaussian elimination method with partial pivoting. */ /* Parameters: */ /* n - number of equations */ /* a[n][n] - coefficient matrix */ /* b[n] - right-hand side vector */ /* *det - determinant of [A] */ int gauss (double a[][MAXSIZE], double b[], int n, double *det) { double tol, temp, mult; int npivot, i, j, l, k, flag; //initialization *det = 1.0; tol = 1e-30; //initial tolerance value npivot = 0; //mult = 0; //forward elimination for (k = 0; k < n; k++) { //search for max coefficient in pivot row- a[k][k] pivot element for (i = k + 1; i < n; i++) { if (fabs(a[i][k]) > fabs(a[k][k])) { //interchange row with maxium element with pivot row npivot++; for (l = 0; l < n; l++) { temp = a[i][l]; a[i][l] = a[k][l]; a[k][l] = temp; } temp = b[i]; b[i] = b[k]; b[k] = temp; } } //test for singularity if (fabs(a[k][k]) < tol) { //matrix is singular- terminate flag = 1; return flag; } //compute determinant- the product of the pivot elements *det = *det * a[k][k]; //eliminate the coefficients of X(I) for (i = k; i < n; i++) { mult = a[i][k] / a[k][k]; b[i] = b[i] - b[k] * mult; //compute constants for (j = k; j < n; j++) //compute coefficients a[i][j] = a[i][j] - a[k][j] * mult; } } //adjust the sign of the determinant if(npivot % 2 == 1) *det = *det * (-1.0); //backsubstitution b[n] = b[n] / a[n][n]; for(i = n - 1; i > 1; i--) { for(j = n; j > i + 1; j--) b[i] = b[i] - a[i][j] * b[j]; b[i] = b[i] / a[i - 1][i]; } flag = 0; return flag; } The solution should be: 1.058824, 1.823529, 0.882353 with det as -102.000000 Any insight is appreciated...

    Read the article

  • improving drawing pythagoras tree

    - by sasquatch90
    Hello. I have written program for drawing pythagoras tree fractal. Can anybody see any way of improving it ? Now it is 120 LOc. I was hoping to shorten it to ~100... import javax.swing.*; import java.util.Scanner; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JComponent; public class Main extends JFrame {; public Main(int n) { setSize(900, 900); setTitle("Pythagoras tree"); Draw d = new Draw(n); add(d); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } private int pow(int n){ int pow = 2; for(int i = 1; i < n; i++){ if(n==0){ pow = 1; } pow = pow*2; } return pow; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Give amount of steps: "); int steps = sc.nextInt(); new Main(steps); } } class Draw extends JComponent { private int height; private int width; private int steps; public Draw(int n) { height = 800; width = 800; steps = n; Dimension d = new Dimension(width, height); setMinimumSize(d); setPreferredSize(new Dimension(d)); setMaximumSize(d); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.white); g.fillRect(0, 0, width, height); g.setColor(Color.black); int w = width; int h = height; int x1, x2, x3, x4, x5, y1, y2, y3, y4, y5; int base = w/7; x1 = (w/2)-(base/2); x2 = x1; x3 = (w/2)+(base/2); x4 = x3; x5 = w/2; y1 = (h-(h/15))-base; y2 = h-(h/15); y3 = y2; y4 = y1; y5 = (h-(h/15))-(base+(base/2)); //paint g.drawLine(x1, y1, x2, y2); g.drawLine(x2, y2, x3, y3); g.drawLine(x3, y3, x4, y4); g.drawLine(x1, y1, x4, y4); int n1 = steps; n1--; if(n1>0){ g.drawLine(x1, y1, x5, y5); g.drawLine(x4, y4, x5, y5); paintMore(n1, g, x1, x5, x4, y1, y5, y4); paintMore(n1, g, x4, x5, x1, y4, y5, y1); } } public void paintMore(int n1, Graphics g, double x1_1, double x2_1, double x3_1, double y1_1, double y2_1, double y3_1){ double x1, x2, x3, x4, x5, y1, y2, y3, y4, y5; //counting x1 = x1_1 + (x2_1-x3_1); x2 = x1_1; x3 = x2_1; x4 = x2_1 + (x2_1-x3_1); x5 = ((x2_1 + (x2_1-x3_1)) + ((x2_1-x3_1)/2)) + ((x1_1-x2_1)/2); y1 = y1_1 + (y2_1-y3_1); y2 = y1_1; y3 = y2_1; y4 = y2_1 + (y2_1-y3_1); y5 = ((y1_1 + (y2_1-y3_1)) + ((y2_1-y1_1)/2)) + ((y2_1-y3_1)/2); //paint g.setColor(Color.green); g.drawLine((int)x1, (int)y1, (int)x2, (int)y2); g.drawLine((int)x3, (int)y3, (int)x4, (int)y4); g.drawLine((int)x1, (int)y1, (int)x4, (int)y4); n1--; if(n1>0){ g.drawLine((int)x1, (int)y1, (int)x5, (int)y5); g.drawLine((int)x4, (int)y4, (int)x5, (int)y5); paintMore(n1, g, x1, x5, x4, y1, y5, y4); paintMore(n1, g, x4, x5, x1, y4, y5, y1); } } }

    Read the article

  • Jframe using multiple classes?

    - by user2945880
    and im trying to make it so it can show multiple classes at once Jframe: import javax.swing.JFrame; import java.awt.BorderLayout; public class Concert { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(1000, 800); frame.setTitle("Concert!"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Concertbackground component = new Concertbackground(); BandComponent component1 = new BandComponent(); frame.add(component, BorderLayout.NORTH); frame.add(component1, BorderLayout.CENTER); frame.setVisible(true); } } These are the two classes mentioned in the Jframe: import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import javax.swing.JComponent; import java.awt.Polygon; /* BandComponent.java Justin Walker 10/27/13 */ public class BandComponent extends JComponent { public void paintComponent(Graphics g) { // Recover Graphics2D Graphics2D g2 = (Graphics2D) g; int xScale = 250; int yScale = 100; int x = 343; int y = 343; //singer Polygon sing = new Polygon(); sing.addPoint(667 ,208 + xScale); sing.addPoint(676,213 + xScale); sing.addPoint(678,217 + xScale); sing.addPoint(682,221 + xScale); sing.addPoint(681,224 + xScale); sing.addPoint(680,231 + xScale); sing.addPoint(676,242 + xScale); sing.addPoint(672,244 + xScale); sing.addPoint(672,250 + xScale); sing.addPoint(682,248 + xScale); sing.addPoint(713,244 + xScale); sing.addPoint(734,247 + xScale); sing.addPoint(750,247 + xScale); sing.addPoint(794,232 + xScale); sing.addPoint(800,231 + xScale); sing.addPoint(801,223 + xScale); sing.addPoint(807,219 + xScale); sing.addPoint(806,221 + xScale); sing.addPoint(806,229 + xScale); sing.addPoint(818,222 + xScale); sing.addPoint(820,223 + xScale); sing.addPoint(825,227 + xScale); sing.addPoint(825,240 + xScale); sing.addPoint(817,243 + xScale); sing.addPoint(807,245 + xScale); sing.addPoint(803,247 + xScale); sing.addPoint(801,252 + xScale); sing.addPoint(781,257 + xScale); sing.addPoint(762,264 + xScale); sing.addPoint(734,271 + xScale); sing.addPoint(701,286 + xScale); sing.addPoint(691,296 + xScale); sing.addPoint(693,311 + xScale); sing.addPoint(690,317 + xScale); sing.addPoint(690,335 + xScale); sing.addPoint(691,339 + xScale); sing.addPoint(689,343 + xScale); sing.addPoint(712,382 + xScale); sing.addPoint(725,400 + xScale); sing.addPoint(731,418 + xScale); sing.addPoint(731,428 + xScale); sing.addPoint(738,454 + xScale); sing.addPoint(741,460 + xScale); sing.addPoint(746,468 + xScale); sing.addPoint(766,468 + xScale); sing.addPoint(771,481 + xScale);// sing.addPoint(723,482 + xScale); sing.addPoint(720,462 + xScale); sing.addPoint(718,454 + xScale); sing.addPoint(709,436 + xScale); sing.addPoint(703,436 + xScale); sing.addPoint(699,417 + xScale); sing.addPoint(686,396 + xScale); sing.addPoint(678,395 + xScale); sing.addPoint(676,437 + xScale); sing.addPoint(673,439 + xScale); sing.addPoint(638,435 + xScale); sing.addPoint(640,398 + xScale); sing.addPoint(634,410 + xScale); sing.addPoint(625,416 + xScale); sing.addPoint(622,436 + xScale); sing.addPoint(622,443 + xScale); sing.addPoint(615,447 + xScale); sing.addPoint(609,456 + xScale); sing.addPoint(606,481 + xScale);// sing.addPoint(557,481 + xScale); sing.addPoint(560,467 + xScale); sing.addPoint(579,467 + xScale); sing.addPoint(587,464 + xScale); sing.addPoint(593,452 + xScale); sing.addPoint(594,441 + xScale); sing.addPoint(592,434 + xScale); sing.addPoint(600,416 + xScale); sing.addPoint(608,405 + xScale); sing.addPoint(609,394 + xScale); sing.addPoint(617,376 + xScale); sing.addPoint(619,363 + xScale); sing.addPoint(632,334 + xScale); sing.addPoint(637,324 + xScale); sing.addPoint(635,314 + xScale); sing.addPoint(639,296 + xScale); sing.addPoint(627,285 + xScale); sing.addPoint(600,279 + xScale); sing.addPoint(582,278 + xScale); sing.addPoint(575,275 + xScale); sing.addPoint(546,256 + xScale); sing.addPoint(536,252 + xScale); sing.addPoint(533,350 + xScale); sing.addPoint(534,361 + xScale); sing.addPoint(532,367 + xScale); sing.addPoint(529,369 + xScale); sing.addPoint(524,363 + xScale); sing.addPoint(525,355 + xScale); sing.addPoint(531,254 + xScale); sing.addPoint(527,249 + xScale); sing.addPoint(527,242 + xScale); sing.addPoint(529,237 + xScale); sing.addPoint(532,237 + xScale); sing.addPoint(536,178 + xScale); sing.addPoint(534,129 + xScale); sing.addPoint(535,123 + xScale); sing.addPoint(541,120 + xScale); sing.addPoint(545,123 + xScale); sing.addPoint(547,131 + xScale); sing.addPoint(545,173 + xScale); sing.addPoint(538,233 + xScale); sing.addPoint(549,239 + xScale); sing.addPoint(558,241 + xScale); sing.addPoint(585,257 + xScale); sing.addPoint(599,257 + xScale); sing.addPoint(627,254 + xScale); sing.addPoint(647,251 + xScale); sing.addPoint(653,248 + xScale); sing.addPoint(652,235 + xScale); sing.addPoint(648,226 + xScale); sing.addPoint(652,218 + xScale); sing.addPoint(661,212 + xScale); g2.setColor(Color.black); g2.fill(sing); g2.draw(sing); //guitar Polygon guitar = new Polygon(); guitar.addPoint(148,28); guitar.addPoint(158,32); guitar.addPoint(164,38); guitar.addPoint(168,46); guitar.addPoint(169,52); guitar.addPoint(167,60); guitar.addPoint(164,65); guitar.addPoint(165,70); guitar.addPoint(161,76); guitar.addPoint(158,92); guitar.addPoint(162,97); guitar.addPoint(161,102); guitar.addPoint(158,106); guitar.addPoint(155,108); guitar.addPoint(151,127); guitar.addPoint(152,133); guitar.addPoint(155,137); guitar.addPoint(151,146); guitar.addPoint(153,147); guitar.addPoint(160,142); guitar.addPoint(162,133); guitar.addPoint(162,123); guitar.addPoint(161,113); guitar.addPoint(162,110); guitar.addPoint(164,117); guitar.addPoint(169,131); guitar.addPoint(171,144); guitar.addPoint(170,159); guitar.addPoint(166,167); guitar.addPoint(166,171); guitar.addPoint(174,174); guitar.addPoint(183,184); guitar.addPoint(191,195); guitar.addPoint(196,198); guitar.addPoint(198,200); guitar.addPoint(199,210); guitar.addPoint(211,225); guitar.addPoint(212,233); guitar.addPoint(220,248); guitar.addPoint(233,260); guitar.addPoint(245,266); guitar.addPoint(248,268); guitar.addPoint(249,277); guitar.addPoint(205,275); guitar.addPoint(204,262); guitar.addPoint(187,238); guitar.addPoint(178,224); guitar.addPoint(177,216); guitar.addPoint(156,201); guitar.addPoint(146,197); guitar.addPoint(134,211); guitar.addPoint(128,229); guitar.addPoint(125,244);// guitar.addPoint(121,246); guitar.addPoint(107,248); guitar.addPoint(100,252); guitar.addPoint(97,258); guitar.addPoint(96,253); guitar.addPoint(89,258); guitar.addPoint(65,267); guitar.addPoint(63,274); guitar.addPoint(64,283); guitar.addPoint(41,282); guitar.addPoint(44,270); guitar.addPoint(47,264); guitar.addPoint(51,255); guitar.addPoint(73,238); guitar.addPoint(79,228); guitar.addPoint(97,222); guitar.addPoint(101,204); guitar.addPoint(102,181); guitar.addPoint(100,170); guitar.addPoint(95,161); guitar.addPoint(97,154); guitar.addPoint(91,152); guitar.addPoint(77,131); guitar.addPoint(65,123); guitar.addPoint(61,105); guitar.addPoint(64,94); guitar.addPoint(72,91); guitar.addPoint(78,82); guitar.addPoint(78,76); guitar.addPoint(70,73); guitar.addPoint(70,67); guitar.addPoint(93,51); guitar.addPoint(101,48); guitar.addPoint(111,52); guitar.addPoint(118,59); guitar.addPoint(119,70); guitar.addPoint(117,78); guitar.addPoint(113,79); guitar.addPoint(112,86); guitar.addPoint(111,88); guitar.addPoint(109,89); guitar.addPoint(109,92); guitar.addPoint(122,99);// guitar.addPoint(124,99); guitar.addPoint(133,96); guitar.addPoint(145,93); //guitar.addPoint(138,124); guitar.addPoint(150,69); guitar.addPoint(150,62); guitar.addPoint(155,58); guitar.addPoint(154,53); guitar.addPoint(149,50); guitar.addPoint(154,46); guitar.addPoint(153,38); guitar.addPoint(147,28); g2.setColor(Color.black); g2.fill(guitar); g2.draw(guitar); Polygon guitar2 = new Polygon (); guitar2.addPoint(141,108); guitar2.addPoint(139,126); guitar2.addPoint(135,122); guitar2.addPoint(128,122); guitar2.addPoint(129,116); guitar2.addPoint(143,108); g2.setColor(Color.white); g2.fill(guitar2); g2.draw(guitar2); //bass guitar Polygon bassgt = new Polygon (); bassgt.addPoint(871,21); bassgt.addPoint(879,24); bassgt.addPoint(885,32); bassgt.addPoint(886,42); bassgt.addPoint(895,47); bassgt.addPoint(904,56); bassgt.addPoint(907,69); bassgt.addPoint(909,83); bassgt.addPoint(910,91); bassgt.addPoint(941,81); bassgt.addPoint(946,75); bassgt.addPoint(945,67); bassgt.addPoint(950,67); bassgt.addPoint(955,75); bassgt.addPoint(960,68); bassgt.addPoint(963,74); bassgt.addPoint(967,72); bassgt.addPoint(971,66); bassgt.addPoint(973,70); bassgt.addPoint(981,67); bassgt.addPoint(984,71); bassgt.addPoint(982,76); bassgt.addPoint(987,80); bassgt.addPoint(986,82); bassgt.addPoint(980,83); bassgt.addPoint(979,90); bassgt.addPoint(974,85); bassgt.addPoint(970,86); bassgt.addPoint(973,91); bassgt.addPoint(965,86); bassgt.addPoint(960,90); bassgt.addPoint(961,100); bassgt.addPoint(955,92); bassgt.addPoint(944,91); bassgt.addPoint(907,103); bassgt.addPoint(906,109); bassgt.addPoint(893,114); bassgt.addPoint(895,123); bassgt.addPoint(900,131); bassgt.addPoint(904,134); bassgt.addPoint(908,145); bassgt.addPoint(911,159); bassgt.addPoint(918,171); bassgt.addPoint(919,190); bassgt.addPoint(923,198); bassgt.addPoint(919,201); bassgt.addPoint(919,210); bassgt.addPoint(927,220); bassgt.addPoint(942,226); bassgt.addPoint(944,234); bassgt.addPoint(909,230); bassgt.addPoint(905,214); bassgt.addPoint(899,204); bassgt.addPoint(893,203); bassgt.addPoint(889,171); bassgt.addPoint(877,151); bassgt.addPoint(861,152); bassgt.addPoint(852,169); bassgt.addPoint(849,203); bassgt.addPoint(841,210); bassgt.addPoint(840,228); bassgt.addPoint(828,233); bassgt.addPoint(806,235); bassgt.addPoint(805,228); bassgt.addPoint(822,219); bassgt.addPoint(824,204); bassgt.addPoint(817,201); bassgt.addPoint(822,196); bassgt.addPoint(822,184); bassgt.addPoint(828,162); bassgt.addPoint(829,152); bassgt.addPoint(820,149); bassgt.addPoint(811,144); bassgt.addPoint(806,134); bassgt.addPoint(805,117); bassgt.addPoint(820,107); bassgt.addPoint(819,89); bassgt.addPoint(811,83); bassgt.addPoint(811,77); bassgt.addPoint(824,66); bassgt.addPoint(825,61); bassgt.addPoint(842,53); bassgt.addPoint(852,43); bassgt.addPoint(853,29); bassgt.addPoint(870,20); g2.setColor(Color.black); g2.fill(bassgt); g2.draw(bassgt); Polygon bassgt2 = new Polygon(); bassgt2.addPoint(845,78); bassgt2.addPoint(845,98); bassgt2.addPoint(843,98); bassgt2.addPoint(842,105); bassgt2.addPoint(839,109); bassgt2.addPoint(834,103); bassgt2.addPoint(832,85); bassgt2.addPoint(845,78); g2.setColor(Color.white); g2.fill(bassgt2); g2.draw(bassgt2); Polygon drums = new Polygon (); drums.addPoint(713,104); drums.addPoint(706,121); drums.addPoint(721,377); drums.addPoint(248,380); drums.addPoint(253,228); drums.addPoint(250,206); drums.addPoint(237,178); drums.addPoint(206,166); drums.addPoint(201,154); drums.addPoint(198,152); drums.addPoint(208,148); drums.addPoint(236,150); drums.addPoint(247,130); drums.addPoint(227,119); drums.addPoint(219,105); drums.addPoint(222,96); drums.addPoint(233,88); drums.addPoint(251,84); drums.addPoint(272,83); drums.addPoint(300,91); drums.addPoint(285,72); drums.addPoint(294,57); drums.addPoint(319,46); drums.addPoint(372,45); drums.addPoint(406,50); drums.addPoint(428,65); drums.addPoint(433,74); drums.addPoint(450,58); drums.addPoint(478,48); drums.addPoint(514,48); drums.addPoint(544,51); drums.addPoint(566,52); drums.addPoint(577,67); drums.addPoint(575,79); drums.addPoint(561,95); drums.addPoint(545,98); drums.addPoint(525,105); drums.addPoint(524,147); drums.addPoint(524,183); drums.addPoint(645,175); drums.addPoint(662,143); drums.addPoint(617,152); drums.addPoint(608,148); drums.addPoint(614,139); drums.addPoint(633,128); drums.addPoint(661,116); drums.addPoint(659,107); drums.addPoint(625,114); drums.addPoint(592,113); drums.addPoint(571,111); drums.addPoint(565,102); drums.addPoint(576,86); drums.addPoint(616,70); drums.addPoint(647,66); drums.addPoint(679,67); drums.addPoint(695,72); drums.addPoint(699,90); drums.addPoint(678,100); drums.addPoint(667,103); drums.addPoint(672,113); drums.addPoint(689,105); drums.addPoint(709,106); g2.setColor(Color.black); g2.fill(drums); g2.draw(drums); } } The second class: import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import javax.swing.JComponent; import java.awt.GradientPaint; /* component that draws the concert background */ public class Concertbackground extends JComponent { public void paintComponent(Graphics g) { super.paintComponent(g); // Recover Graphics2D Graphics2D g2 = (Graphics2D) g; //Background Top g2.setColor(Color.BLUE); Rectangle backgroundTop = new Rectangle (0, 0, getWidth(), getHeight() / 4); g2.fill(backgroundTop); // Background bottom g2.setColor(Color.GREEN); Rectangle backgroundBottom = new Rectangle (0, getHeight() / 2, getWidth(), getHeight() / 2); g2.fill(backgroundBottom); // Speaker base g2.setColor(Color.BLACK); Rectangle base = new Rectangle (0, 0, 50, 100); g2.fill(base); // Speakers circles gray top g2.setColor(Color.DARK_GRAY); Ellipse2D.Double speakerTop = new Ellipse2D.Double(10, 10, 30, 30); g2.fill(speakerTop); //speakers circles black top g2.setColor(Color.BLACK); Ellipse2D.Double speakerTop1 = new Ellipse2D.Double(15, 15, 20, 20); g2.fill(speakerTop1); // Speakers circles gray bottom g2.setColor(Color.DARK_GRAY); Ellipse2D.Double speakerBottom = new Ellipse2D.Double(10, 50, 30, 30); g2.fill(speakerBottom); //speakers circles black bottom g2.setColor(Color.BLACK); Ellipse2D.Double speakerBottom1 = new Ellipse2D.Double(15, 55, 20, 20); g2.fill(speakerBottom1); } } My main question is how do I change my Jframe so it can use as many classes as I want, It cant be the size of my classes because they were used with the same 1000, 800 Jframe to make the classes. I also need to be able to add more than just these two classes to my Jframe.

    Read the article

  • Motorola NVG510 bridge mode

    - by Blacklight Shining
    I have a Motorola NVG510 modem from AT&T, and I would like to disable all routing functions and use it as just a modem. I have a Time Capsule that's already connected and broadcasting its own wireless network, which is how I've been connecting (it's been reporting a double-NAT error, which I assume is from the NVG510 also acting as a router). I followed the instructions in question six here, and I can connect as I did before, but my Time Capsule still has a double-NAT error. How do I put the NVG510 into bridge mode or otherwise fix the double-NAT error? (No, ignoring it does not count as a fix.)

    Read the article

  • operator overloading of stream extraction operator in C++ help

    - by Crystal
    I'm having some trouble overloading my stream extraction operator in C++ for a hw assignment. I'm not really sure why I am getting these compile errors since I thought I was doing it right... Here is my code: Complex.h #ifndef COMPLEX_H #define COMPLEX_H class Complex { //friend ostream &operator<<(ostream &output, const Complex &complexObj) const; public: Complex(double = 0.0, double = 0.0); // constructor Complex operator+(const Complex &) const; // addition Complex operator-(const Complex &) const; // subtraction void print() const; // output private: double real; // real part double imaginary; // imaginary part }; #endif Complex.cpp #include <iostream> #include "Complex.h" using namespace std; // Constructor Complex::Complex(double realPart, double imaginaryPart) : real(realPart), imaginary(imaginaryPart) { } // addition operator Complex Complex::operator+(const Complex &operand2) const { return Complex(real + operand2.real, imaginary + operand2.imaginary); } // subtraction operator Complex Complex::operator-(const Complex &operand2) const { return Complex(real - operand2.real, imaginary - operand2.imaginary); } // Overload << operator ostream &Complex::operator<<(ostream &output, const Complex &complexObj) const { cout << '(' << complexObj.real << ", " << complexObj.imaginary << ')'; return output; // returning output allows chaining } // display a Complex object in the form: (a, b) void Complex::print() const { cout << '(' << real << ", " << imaginary << ')'; } main.cpp #include <iostream> #include "Complex.h" using namespace std; int main() { Complex x; Complex y(4.3, 8.2); Complex z(3.3, 1.1); cout << "x: "; x.print(); cout << "\ny: "; y.print(); cout << "\nz: "; z.print(); x = y + z; cout << "\n\nx = y + z: " << endl; x.print(); cout << " = "; y.print(); cout << " + "; z.print(); x = y - z; cout << "\n\nx = y - z: " << endl; x.print(); cout << " = "; y.print(); cout << " - "; z.print(); cout << endl; } Compile erros: complex.cpp(23) : error C2039: '<<' : is not a member of 'Complex' complex.h(5) : see declaration of 'Complex' complex.cpp(24) : error C2270: '<<' : modifiers not allowed on nonmember functions complex.cpp(25) : error C2248: 'Complex::real' : cannot access private member declared in class 'Complex' complex.h(13) : see declaration of 'Complex::real' complex.h(5) : see declaration of 'Complex' complex.cpp(25) : error C2248: 'Complex::imaginary' : cannot access private member declared in class 'Complex' complex.h(14) : see declaration of 'Complex::imaginary' complex.h(5) : see declaration of 'Complex' Thanks!

    Read the article

  • VLC - Adding to playlist

    - by VANJ
    I am using Songr to find/stream songs and double click them to play in VLC which basically "plays" the URL. But as I am listening to one item and search for another and double click another item from the results, it replaces the currently playing item in VLC. How do I set it up such that double clicking adds to the current playlist? When I see now is that it adds the new item to the end of the playlist and proceeds to play it. Any ideas? Thanks

    Read the article

  • Best way to upscale a video?

    - by Josh
    If I have a video file at 320x240 resolution which I want to re-encode (because I don't like the encoding it's in now) and I also want to play it at double size (640x480), will I get higher quality if I scale it up to 640x480 when I convert it to a new format, verses keeping it at 320x240 in the new format and playing it at double size? This probably depends on the program used to convert, and if so, please let me know any program which might increase the quality. Here's my thinking. If I play a 320x240 file at double size, the system has to scale up each frame in real time, whereas if I scale up while recompressing the system may be able to use a more intensive algorythm like Bicubic interpolation . However I am not sure if this is true or not.

    Read the article

  • Cannot install FrontPage 2002 Server Extensions on Server 2003

    - by Sentax
    Hi everyone, I've followed the Microsoft article to install FPSE 2002 on my Windows 2003 server: To install and enable FrontPage 2002 Server Extensions 1. From the Start menu, click Control Panel. 2. Double-click Add or Remove Programs. 3. Click Add/Remove Windows Components. 4. In the Windows Components Wizard, double-click Application Server, double-click Internet Information Services, and then select the FrontPage 2002 Server Extensions check box. 5. Click OK twice, click Next, and then click Finish. But on step 4 "FrontPage 2002 Server Extensions" does not show up in the list in the IIS details window. How do I get FPSE 2002 installed on my server? From what I can understand it's supposed to be there and I just have to enable it. But that's not an option for me. Thanks.

    Read the article

  • Algorithm for dragging objects on a fixed grid

    - by FlyingStreudel
    Hello, I am working on a program for the mapping and playing of the popular tabletop game D&D :D Right now I am working on getting the basic functionality like dragging UI elements around, snapping to the grid and checking for collisions. Right now every object when released from the mouse immediately snaps to the nearest grid point. This causes an issue when something like a player object snaps to a grid point that has a wall -or other- adjacent. So essentially when the player is dropped they wind up with some of the wall covering them. This is fine and working as intended, however the problem is that now my collision detection is tripped whenever you try to move this player because its sitting underneath a wall and because of this you cant drag the player anymore. Here is the relevant code: void UIObj_MouseMove(object sender, MouseEventArgs e) { blocked = false; if (dragging) { foreach (UIElement o in ((Floor)Parent).Children) { if (o.GetType() != GetType() && o.GetType().BaseType == typeof(UIObj) && Math.Sqrt(Math.Pow(((UIObj)o).cX - cX, 2) + Math.Pow(((UIObj)o).cY - cY, 2)) < Math.Max(r.Height + ((UIObj)o).r.Height, r.Width + ((UIObj)o).r.Width)) { double Y = e.GetPosition((Floor)Parent).Y; double X = e.GetPosition((Floor)Parent).X; Geometry newRect = new RectangleGeometry(new Rect(Margin.Left + (X - prevX), Margin.Top + (Y - prevY), Margin.Right + (X - prevX), Margin.Bottom + (Y - prevY))); GeometryHitTestParameters ghtp = new GeometryHitTestParameters(newRect); VisualTreeHelper.HitTest(o, null, new HitTestResultCallback(MyHitTestResultCallback), ghtp); } } if (!blocked) { Margin = new Thickness(Margin.Left + (e.GetPosition((Floor)Parent).X - prevX), Margin.Top + (e.GetPosition((Floor)Parent).Y - prevY), Margin.Right + (e.GetPosition((Floor)Parent).X - prevX), Margin.Bottom + (e.GetPosition((Floor)Parent).Y - prevY)); InvalidateVisual(); } prevX = e.GetPosition((Floor)Parent).X; prevY = e.GetPosition((Floor)Parent).Y; cX = Margin.Left + r.Width / 2; cY = Margin.Top + r.Height / 2; } } internal virtual void SnapToGrid() { double xPos = Margin.Left; double yPos = Margin.Top; double xMarg = xPos % ((Floor)Parent).cellDim; double yMarg = yPos % ((Floor)Parent).cellDim; if (xMarg < ((Floor)Parent).cellDim / 2) { if (yMarg < ((Floor)Parent).cellDim / 2) { Margin = new Thickness(xPos - xMarg, yPos - yMarg, xPos - xMarg + r.Width, yPos - yMarg + r.Height); } else { Margin = new Thickness(xPos - xMarg, yPos - yMarg + ((Floor)Parent).cellDim, xPos - xMarg + r.Width, yPos - yMarg + ((Floor)Parent).cellDim + r.Height); } } else { if (yMarg < ((Floor)Parent).cellDim / 2) { Margin = new Thickness(xPos - xMarg + ((Floor)Parent).cellDim, yPos - yMarg, xPos - xMarg + ((Floor)Parent).cellDim + r.Width, yPos - yMarg + r.Height); } else { Margin = new Thickness(xPos - xMarg + ((Floor)Parent).cellDim, yPos - yMarg + ((Floor)Parent).cellDim, xPos - xMarg + ((Floor)Parent).cellDim + r.Width, yPos - yMarg + ((Floor)Parent).cellDim + r.Height); } } } Essentially I am looking for a simple way to modify the existing code to allow the movement of a UI element that has another one sitting on top of it. Thanks!

    Read the article

  • Re-encoding a video file and increasing the size -- does this improve the quality?

    - by Josh
    If I have a video file at 320x240 resolution which I want to re-encode (because I don't like the encoding it's in now) and I also want to play it at double size (640x480), will I get higher quality if I scale it up to 640x480 when I convert it to a new format, verses keeping it at 320x240 in the new format and playing it at double size? This probably depends on the program used to convert, and if so, please let me know any program which might increase the quality. Here's my thinking. If I play a 320x240 file at double size, the system has to scale up each frame in real time, whereas if I scale up while recompressing the system may be able to use a more intensive algorythm like Bicubic interpolation . However I am not sure if this is true or not.

    Read the article

  • Printing out variables in c changes values of variables

    - by George Wilson
    I have an odd problem with some c-programme here. I was getting some wrong values in a matrix I was finding the determinant of and so I started printing variables - yet found that by printing values out the actual values in the code changed. I eventually narrowed it down to one specific printf statement - highlighted in the code below. If I comment out this line then I start getting incorrect values in my determinent calculations, yet by printing it out I get the value out I expect Code below: #include <math.h> #include <stdio.h> #include <stdlib.h> #define NUMBER 15 double determinant_calculation(int size, double array[NUMBER][NUMBER]); int main() { double array[NUMBER][NUMBER], determinant_value; int size; array[0][0]=1; array[0][1]=2; array[0][2]=3; array[1][0]=4; array[1][1]=5; array[1][2]=6; array[2][0]=7; array[2][1]=8; array[2][2]=10; size=3; determinant_value=determinant_calculation(size, array); printf("\n\n\n\n\n\nDeterminant value is %lf \n\n\n\n\n\n", determinant_value); return 0; } double determinant_calculation(int size, double array[NUMBER][NUMBER]) { double determinant_matrix[NUMBER][NUMBER], determinant_value; int x, y, count=0, sign=1, i, j; /*initialises the array*/ for (i=0; i<(NUMBER); i++) { for(j=0; j<(NUMBER); j++) { determinant_matrix[i][j]=0; } } /*does the re-cursion method*/ for (count=0; count<size; count++) { x=0; y=0; for (i=0; i<size; i++) { for(j=0; j<size; j++) { if (i!=0&&j!=count) { determinant_matrix[x][y]=array[i][j]; if (y<(size-2)) { y++; } else { y=0; x++; } } } } //commenting this for loop out changes the values of the code determinent prints -7 when commented out and -3 (expected) when included! for (i=0; i<size; i++) { for(j=0; j<size; j++){ printf("%lf ", determinant_matrix[i][j]); } printf("\n"); } if(size>2) { determinant_value+=sign*(array[0][count]*determinant_calculation(size-1 ,determinant_matrix)); } else { determinant_value+=sign*(array[0][count]*determinant_matrix[0][0]); } sign=-1*sign; } return (determinant_value); } I know its not the prettiest (or best way) of doing what I'm doing with this code but it's what I've been given - so can't make huge changes. I don't suppose anyone could explain why printing out the variables can actually change the values? or how to fix it because ideally i don't want to!!

    Read the article

  • Share iTunes Library from Nas across several clients. How in Windows

    - by Mych
    I found this article http://gigaom.com/apple/one-itunes-library-on-multiple-computers/ which describes sharing a single library with multiple clients. Unfortunately this article is for Macs and I use Windows. The article mentions 3 jobs that need to be completed.' A) - pointing all clients to the location of the Library. This is understandable and I can replicate using windows clients. B) Universal Library Set-up. This mentions holing the option key and double click iTunes icon. This is so you can create the index at a specific location C) Point clients to index. Again this mentions Option double click. What is the Windows equivalent to option double click iTunes?

    Read the article

  • why is my intent not useful?

    - by user1634887
    This is my first to ask here. I write the code for a Broadcast A start another Broadcast B. But the Broadcast B didn't get the intent's value. Broadcast A:get the sms contain message and start B public void onReceive(Context context, Intent intent) { Object[] pdus=(Object[])intent.getExtras().get("pdus"); for(Object pdu:pdus) { byte[] date=(byte[])pdu; SmsMessage message=SmsMessage.createFromPdu(date); String sender=message.getOriginatingAddress(); String body=message.getMessageBody(); if(sender.equals(AppUtil.herPhone)&&body.regionMatches(0, AppUtil.herSmsText, 0, 18)) { Toast.makeText(context, body, Toast.LENGTH_LONG).show(); String [] bodyArray=body.split(" "); String longitude=bodyArray[1]; String latitude=bodyArray[2]; **Intent uiIntent=new Intent(); Bundle bundle=new Bundle(); bundle.putString("longitude", longitude); bundle.putString("latitude", latitude); uiIntent.putExtras(bundle); uiIntent.setAction("android.janmac.location"); context.sendBroadcast(uiIntent);** abortBroadcast(); } } } Boardcast B: it nest in an Activity. register: button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AppUtil.SendMessage(MainActivity.this); uiReceiver=new UIReceiver(); IntentFilter filter=new IntentFilter(); filter.addAction("android.janmac.location"); registerReceiver(uiReceiver, filter); } }); extend: private class UIReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.v("location","uireceiver????!"); **Bundle bundle=new Bundle(); bundle=intent.getExtras(); herLongitude=Double.valueOf(bundle.getString("longitude")); herLatitude=Double.valueOf(bundle.getString("latitude"));** } } but the bundle couldn't get any values. here is log: 08-30 11:17:40.494: D/AndroidRuntime(2359): Shutting down VM 08-30 11:17:40.514: W/dalvikvm(2359): threadid=1: thread exiting with uncaught exception (group=0x40018560) 08-30 11:17:40.544: E/AndroidRuntime(2359): FATAL EXCEPTION: main 08-30 11:17:40.544: E/AndroidRuntime(2359): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.janmac.location (has extras) } in com.example.locationclient.MainActivity$UIReceiver@40513690 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.os.Handler.handleCallback(Handler.java:587) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.os.Handler.dispatchMessage(Handler.java:92) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.os.Looper.loop(Looper.java:130) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.app.ActivityThread.main(ActivityThread.java:3835) 08-30 11:17:40.544: E/AndroidRuntime(2359): at java.lang.reflect.Method.invokeNative(Native Method) 08-30 11:17:40.544: E/AndroidRuntime(2359): at java.lang.reflect.Method.invoke(Method.java:507) 08-30 11:17:40.544: E/AndroidRuntime(2359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) 08-30 11:17:40.544: E/AndroidRuntime(2359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) 08-30 11:17:40.544: E/AndroidRuntime(2359): at dalvik.system.NativeStart.main(Native Method) 08-30 11:17:40.544: E/AndroidRuntime(2359): Caused by: java.lang.NumberFormatException 08-30 11:17:40.544: E/AndroidRuntime(2359): at org.apache.harmony.luni.util.FloatingPointParser.parseDblImpl(Native Method) 08-30 11:17:40.544: E/AndroidRuntime(2359): at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:283) 08-30 11:17:40.544: E/AndroidRuntime(2359): at java.lang.Double.parseDouble(Double.java:318) 08-30 11:17:40.544: E/AndroidRuntime(2359): at java.lang.Double.valueOf(Double.java:356) 08-30 11:17:40.544: E/AndroidRuntime(2359): at com.example.locationclient.MainActivity$UIReceiver.onReceive(MainActivity.java:231) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709) 08-30 11:17:40.544: E/AndroidRuntime(2359): ... 9 more enter code here

    Read the article

  • SQL SERVER – Find Max Worker Count using DMV – 32 Bit and 64 Bit

    - by pinaldave
    During several recent training courses, I found it very interesting that Worker Thread is not quite known to everyone despite the fact that it is a very important feature. At some point in the discussion, one of the attendees mentioned that we can double the Worker Thread if we double the CPU (add the same number of CPU that we have on current system). The same discussion has triggered this quick article. Here is the DMV which can be used to find out Max Worker Count SELECT max_workers_count FROM sys.dm_os_sys_info Let us run the above query on my system and find the results. As my system is 32 bit and I have two CPU, the Max Worker Count is displayed as 512. To address the previous discussion, adding more CPU does not necessarily double the Worker Count. In fact, the logic behind this simple principle is as follows: For x86 (32-bit) upto 4 logical processors  max worker threads = 256 For x86 (32-bit) more than 4 logical processors  max worker threads = 256 + ((# Procs – 4) * 8) For x64 (64-bit) upto 4 logical processors  max worker threads = 512 For x64 (64-bit) more than 4 logical processors  max worker threads = 512+ ((# Procs – 4) * 8) In addition to this, you can configure the Max Worker Thread by using SSMS. Go to Server Node >> Right Click and Select Property >> Select Process and modify setting under Worker Threads. According to Book On Line, the default Worker Thread settings are appropriate for most of the systems. Reference: Pinal Dave (http://blog.SQLAuthority.com) Filed under: Pinal Dave, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology Tagged: SQL DMV

    Read the article

< Previous Page | 50 51 52 53 54 55 56 57 58 59 60 61  | Next Page >