class MyPanel extends JPanel implements Observer, MouseMotionListener, MouseListener { private MyModel model; private View view;  private String mode;  private Rectangle rectangle; private Square square;  public MyPanel(MyModel model, View view) {     this.setBackground(Color.black);     this.setPreferredSize(new Dimension(300, 300));     this.addMouseListener(this);     this.addMouseMotionListener(this);     this.model = model;     this.model.addObserver(this);  }  public void paintComponent(Graphics g) {      super.paintComponent(g);     Graphics2D g2d = (Graphics2D) g;      ArrayList&lt;Rectangle&gt; rectangles = this.model.getRectangles();     for (Rectangle r : getRectangles()) {          int width = Math.abs(r.getStartPoint().getX() - r.getEndPoint().getX());         int height = Math.abs(r.getStartPoint().getY() - r.getEndPoint().getY());     }      ArrayList&lt;Square&gt; squares = this.model.getSquares();      for (Square sqr : getSquares()) {          int xPosition = Math.min(sqr.getStartPoint().getX(), sqr.getEndPoint().getX());         int yPosition = Math.min(sqr.getStartPoint().getY(), sqr.getEndPoint().getY());         int width = Math.abs(sqr.getStartPoint().getX() - sqr.getEndPoint().getX());         int height = Math.abs(sqr.getStartPoint().getY() - sqr.getEndPoint().getY());            }      g2d.dispose(); }  public void update(Observable o, Object arg) {     this.repaint(); }  @Override public void mouseDragged(MouseEvent e) {      if (this.mode.equals("Rectangle")) {          this.rectangle.setEndPoint(e.getX(), e.getY());         this.model.addRectangle(this.rectangle);     }      else if (this.mode.equals("Square")) {           // What code should I add here?          this.model.addSquare(this.square);      }  }  // MouseListener below @Override public void mouseClicked(MouseEvent e) {}  @Override public void mousePressed(MouseEvent e) {      if (this.mode.equals("Rectangle")) {         this.rectangle = new Rectangle(e.getX(), e.getY());     }      else if (this.mode.equals("Square")) {         this.square = new Square(e.getX(), e.getY());      } }  @Override public void mouseReleased(MouseEvent e) {      if (this.mode.equals("Rectangle")) {          this.rectangle.setEndPoint(e.getX(), e.getY());         this.model.addRectangle(this.rectangle);         this.rectangle = null;     }      else if (this.mode.equals("Square")) {         this.model.addSquare(this.square);         this.square = null;     }  }  @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseExited(MouseEvent e) {}   }  The user chooses a mode, rectangle or square. Then they can draw a square or a rectangle with their mouse (live feedback is shown). Here is my drawing panel class. I was successfully able to implement the rectangle mode. The user can draw a rectangle and as they move their mouse, the rectangle is shown in mid construction. I want to do the same for the square mode. For some reason, I'm having a hard time doing this. How would I show a perfect square in mid construction when the user is moving their mouse and how would I draw it once released? What code should I add to my paintComponent method, mouseDragged, mousePressed and mouseReleased method to do this? It was easy for a rectangle because there was no constraint but I'm not sure how to do it for a square with my current implementation.
93
I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.  Is == bad? When should it and should it not be used? What's the difference?
80858
I constantly create square background which I should adjust to artboard size.   Almost every time I miss one or two pixels (Retina is good for that), so I looked for one-click feature "click object to artboard size" and didn't find it.  Probably there is a faster way instead of inserting exact parameters of the artboard to the square dimensions?  Illustrator CS6.   Thanks.
15268
I have a model which you can see here (camera perspective).    In the second image, you can see how the render turned out.    I'm at my wit's end trying to figure our why it's not showing up in the render. If anyone needs more information, just ask and I'll get it to you. I've already checked the normals and they're not the cause.
59355
DataGridView, for example, lets you do this:  DataGridView dgv = ...; DataGridViewCell cell = dgv[1,5];   but for the life of me I can't find the documentation on the index/square-bracket operator.  What do they call it?  Where is it implemented?  Can it throw?  How can I do the same thing in my own classes?  ETA: Thanks for all the quick answers.  Briefly: the relevant documentation is under the "Item" property; the way to overload is by declaring a property like public object this[int x, int y]{ get{...}; set{...} }; the indexer for DataGridView does not throw, at least according to the documentation.  It doesn't mention what happens if you supply invalid coordinates.  ETA Again: OK, even though the documentation makes no mention of it (naughty Microsoft!), it turns out that the indexer for DataGridView will in fact throw an ArgumentOutOfRangeException if you supply it with invalid coordinates.  Fair warning.
108187
I am trying to add simple legend to the map.  I wrote some simple test code below to see what happens but it did not work.  var map = activeView.FocusMap;              IGraphicsContainer graphicsContainer = activeView.GraphicsContainer;             IMapFrame mapFrame = graphicsContainer.FindFrame(map) as IMapFrame;             UID uid = new UID();             uid.Value = "esriCarto.Legend";             IMapSurround mapSurround = map.CreateMapSurround(uid, null); mapFrame.CreateSurroundFrame(uid, null);              var legend = (ILegend)mapSurround;              var legendItem = new VerticalLegendItemClass();             legendItem.HeadingSymbol.Text = "served";             legend.AddItem(legendItem);              var legendItema = new VerticalLegendItemClass();             legendItema.HeadingSymbol.Text = "unserved";             legend.AddItem(legendItema);               IElement element = legend as IElement;             element.Geometry = envelope as IGeometry;             graphicsContainer.AddElement(element, 0);              activeView.Refresh();   The legend I am after, must be similar to this:    Can anyone assist?
108478
I got this identifier inputevenmousebutton is not declared in the current scope; should I use another identifier?  func _ready():     position = get_viewport_rect().size / 2     direction.x = rand_range(-1, 1)     direction.y = rand_range(-1, 1)     direction = direction.normalized()     width = get_viewport_rect().size.x     height = get_viewport_rect().size.y  func _process(delta):     position += direction * speed * delta     if position.x &lt; 0 or position.x &gt; width:         direction.x = -direction.x     if position.y &lt; 0 or position.y &gt; height:         direction.y = -direction.y  func _on_UFO_input_event( viewport, event, shape_idx ):     if event is InputEvenMouseButton and event.button_index ==          BUTTON_LEFT and event.pressed:         direction.x = rand_range(-1, 1)         direction.y = rand_range(-1, 1)           direction = direction.normalized()         position.x = rand_range(1, width -1)         position.y = rand_range(1, height -1)         speed += 5
116183
I tried to draw a  (Lebesgue curve) by using  example for Hilbert curves. But I don't see why it does not work.   \documentclass[12pt]{article}  \usepackage{tikz} \usepackage{ifthen}  \usepackage[position=top,labelformat=empty]{subfig} \usepackage{verbatim}  \newdimen\HilbertLastX \newdimen\HilbertLastY \newcounter{HilbertOrder}  \def\DrawToNext#1#2{%    \advance \HilbertLastX by #1    \advance \HilbertLastY by #2    \pgfpathlineto{\pgfqpoint{\HilbertLastX}{\HilbertLastY}} }  % \Hilbert[right_x,right_y,left_x,left_x,up_x,up_y,down_x,down_y] \def\Hilbert[#1,#2,#3,#4,#5,#6,#7,#8] {   \ifnum\value{HilbertOrder} &gt; 0%      \addtocounter{HilbertOrder}{-1}      \Hilbert[#5,#6,#7,#8,#1,#2,#3,#4]      \Hilbert[#1,#2,#3,#4,#5,#6,#7,#8]      \DrawToNext {#1} {#5}      \Hilbert[#1,#2,#3,#4,#5,#6,#7,#8]      \DrawToNext {#3} {#3}      \Hilbert[#7,#8,#5,#6,#3,#4,#1,#2]      \DrawToNext {#1} {#5}      \addtocounter{HilbertOrder}{1}   \fi }  \def\hilbert((#1,#2),#3){%    \advance \HilbertLastX by #1    \advance \HilbertLastY by #2    \pgfpathmoveto{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}    \setcounter{HilbertOrder}{#3}    \Hilbert[1mm,0mm,-1mm,0mm,0mm,1mm,0mm,-1mm]    \pgfusepath{stroke}% }  \begin{document} \begin{figure}%     \centering     \subfloat[$n=1$]{\tikz[scale=18] \hilbert((0mm,0mm),1);}~~     \subfloat[$n=2$]{\tikz[scale=6] \hilbert((0mm,0mm),2);}~~     \subfloat[$n=3$]{\tikz[scale=2.6] \hilbert((0mm,0mm),3);}~~     \subfloat[$n=4$]{\tikz[scale=1.2] \hilbert((0mm,0mm),4);}~~     \subfloat[$n=5$]{\tikz[scale=0.58] \hilbert((0mm,0mm),5);}% \end{figure}%  \end{document}   I get this result which is obviously wrong:    Any suggestions how to make it work? Thank you!
78597
I keep getting the System.NullPointerException: Attempt to de-reference a null object on my trigger at line 21. I've attempted to add != null to that line and I get an error too. Please see the code below.  trigger UpdateDMAAccount on Account (before insert, before update) { //get set of Postal Codes from leads to be inserted or updated Set&lt;String&gt; BillingpostalCodes = new Set&lt;String&gt;(); for(Account l : trigger.new){ if(l.BillingPostalCode != null){     BillingpostalCodes.add(l.BillingPostalCode);  } } if(BillingpostalCodes.size() &gt; 0){ //create Map of custom object records with Name (PostalCode) as key Map&lt;String,DMA_Value__c&gt; validBillingPostalCode = new Map&lt;String,DMA_Value__c&gt;(); for(DMA_Value__c obj : [SELECT Id, Name, DMA_Value__c FROM DMA_Value__c WHERE Name IN :BillingpostalCodes]){     validBillingPostalCode.put(obj.Name,obj); } for(Account l : trigger.new){     if((Trigger.isInsert || trigger.oldMap.get(l.Id).BillingPostalCode != l.BillingPostalCode) &amp;&amp; validBillingPostalCode.containsKey(l.BillingPostalCode)){          l.DMA__c = validBillingPostalCode.get(l.BillingPostalCode).DMA_Value__c;     }     else if(trigger.oldMap.get(l.Id).BillingPostalCode != NULL || l.BillingPostalCode &amp;&amp; !validBillingPostalCode.containsKey(l.BillingPostalCode)){         //blank value if new PostalCode does not match a record in the Map         l.DMA__c = Null;     }   }  } }
103348
I have an issue with the answer given in this .  As suggested in the comments to its answer, I modified the solution as follows:  \documentclass{article} \usepackage{tikz} \usetikzlibrary{shapes.geometric, arrows} \usetikzlibrary{calc,positioning}  \newcounter{image} \setcounter{image}{0}  \tikzstyle{square} = [draw, rectangle, draw=black, minimum width=1cm, minimum height=1cm, text centered]  \tikzset{drawinside/.code args={#1}{         \draw($(#1.west)!0.3!(#1.center)$)--($(#1.east)!0.3!(#1.center)$);         \draw($(#1.south)!0.3!(#1.center)$)--($(#1.north)!0.3!(#1.center)$);         \draw($(#1.south west)!0.4!(#1.west)!0.3!(#1.center)$)--($(#1.south west)!0.165!(#1.west)!0.5!(#1.center)$)--(#1.center);         \draw(#1.center)--($(#1.north east)!0.165!(#1.east)!0.65!(#1.center)$)--($(#1.north east)!0.45!(#1.east)!0.45!(#1.center)$);                } }  \tikzset{record/.style args={#1 and #2}{         rectangle,draw,minimum width=#1, minimum height=#2     } }  \newcommand{\drawrecord}[1] { \stepcounter{image} { \node [record=1 cm and 1 cm, name=a\theimage] at {#1}; } \node[drawinside={a\theimage}]{}; }  \begin{document} \begin{tikzpicture}  \drawrecord{0,0};  \node (sq) [square] {}; \drawrecord{sq};  \end{tikzpicture} \end{document}   but I keep receiving a ! Package tikz Error: Cannot parse this coordinate. error when I call \drawrecord  . how may I solve this issue?  . Is there a way to define \drawrecord as a \tikzstyle instead of a new command?  EDIT:  for the second question, I have been suggested to look into "append after command", but I cannot find documentation about it, anyone has a link?  EDIT2: actually, the second question is kind of redundant, I can simply call  \node [record=1 cm and 1 cm, name=newnode, right of=oldnode]; \node[drawinside={newnode}]{};   in my document. And  \tikzset{drawinside/.code args={#1}{     \draw($(#1.west)!0.3!(#1.center)$)--($(#1.east)!0.3!(#1.center)$);     \draw($(#1.south)!0.3!(#1.center)$)--($(#1.north)!0.3!(#1.center)$);     \draw($(#1.south west)!0.4!(#1.west)!0.3!(#1.center)$)--($(#1.south west)!0.165!(#1.west)!0.5!(#1.center)$)--(#1.center);     \draw(#1.center)--($(#1.north east)!0.165!(#1.east)!0.5!(#1.center)$)--($(#1.north east)!0.4!(#1.east)!0.3!(#1.center)$);             } }   is symmetrical (the previous one is slightly off)
74735
When I press P to play everything shows up white in the BGE. Shading is set to GLSL, and the objects are UV mapped and textured. It seems that vertex paint is overriding the material for the object even though it is unchecked in the material options.   Shading is set to GLSL   Objects have a texture applied
75110
I have clicked an image in a slide show and it generates a new window. Once the window opens I need to bring focus on new window and do some stuff. I have attached my code below, but it is not successful.  @Test public void testCreateAccount() throws Exception{  //OPEN manorama online  url driver.navigate().to("http://www.manoramaonline.com/cgi-bin/MMOnline.dll/portal/ep/home.do?tabId=0&amp;BV_ID=@@@");  // to click a link inside a slide show  while (!driver         .findElement(                 By.xpath("/html/body/div[2]/div[2]/div[4]/div/div/div/div/center/div/div[2]/span/div/a/img"))         .isDisplayed()) { } driver.findElement(         By.xpath("/html/body/div[2]/div[2]/div[4]/div/div/div/div/center/div/div[2]/span/div/a/img"))         .click();    String newwindowTitle = driver.getTitle();  switchWindow(newwindowTitle);  }  protected static boolean switchWindow(String title) throws IOException {      String currentWindow = driver.getWindowHandle();     Set&lt;String&gt; availableWindows = driver.getWindowHandles();     if (!availableWindows.isEmpty()) {     for (String windowId : availableWindows) {     if (driver.switchTo().window(windowId).getTitle().equals(title)) {     return true;     } else {         driver.switchTo().window(currentWindow);     }}}      return false;        }
70680
I was loading an image resource with the following code and it works fine from my dev environment (netbeans) but threw an exception as soon as it ran from the desktop.  new ImageIcon(Images.class.getResource("images/highlighter24.gif"));   I traced it down to my file having different case than in the code.  Fine, my bad, but why the inconsistent behavior?  Gremlins?  Note: I'm running on windows before you ask.
14954
I am currently building a game where I need to generate some wires (as Bézier curves) using LineRenderer. After changing the width of each line  lineRenderer.SetWidth (0.15f, 0.15f);   I am attaching an EdgeCollider2D to the same game object (specifying the same points used in generating the Bézier curve). This seems to work. However, I would like to be able to know if the Mouse Pointer is at any time over the EdgeCollider2D (something similar to the popular Fruit Ninja game). I'm using Raycast as follows:  void CastRay() {     Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);     RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity);      if (hit) {         Debug.Log (hit.collider.gameObject.name);     } }   I'm calling the CastRay method inside the Update method. Because EdgeCollider2D does not have width (as expected), the log message is never produced.  Do I need to use a different type of Collider? Do I need to call CastRay somewhere else?
64954
I have downloaded a free model for my current project and spotted those different colors on Scale, Rotation, Location, and other properties. What do these different colors signify? What is the meaning of various possible color overlays on UI properties buttons? The very same model after Ctrl + C Ctrl + V to my project file disappeared after a while.
10793
The model is vivisected right down the middle along the z axis. The right leg is rendering funny and I assume if I can get that fixed everything else will fall into place. I tried flipping normals, changing shading types - can't think of anything else to do.
49686
Sometimes when I am debugging code in Eclipse it happens that although I can see and inspect class member variables without any difficulty I am unable to inspect the values of variables declared locally within functions. As an aside, any parameters to the current function lose their 'real' names and instead one sees their values listed in the Variables window as arg0, arg1, arg2, etc but at least the values are visible.  This is occurring at present in relation to classes defined within the core JDK. I have verified that the installed and current JRE is a JDK.  Is anybody able to shed some light on this behaviour?
73868
I need help. I am currently trying to test this code before uploading  public class CoreValuesExt { ApexPages.StandardController sc; public boolean readonly {get; set;} public Core_Values__c cv {get; set;} public integer countEdit = 1; public string buttonValue {get; set;} public integer recordScan;  public CoreValuesExt(ApexPages.StandardController sc) {     this.sc = sc;     cv = new Core_Values__c();     cv.Account__c = sc.getid();      readonly = true;     buttonValue = 'Edit';     recordScan = [SELECT COUNT() FROM Core_Values__c WHERE Account__c = :cv.Account__c];    if (recordScan != 0){    cv = [SELECT id, HSE__c, Professionalism_Integrity__c, Quality_Accuracy__c, Technology_Innovation__c, Timeliness__c, Value_for_money__c FROM Core_Values__c WHERE Account__c = :cv.Account__c];     }  }  public ApexPages.PageReference Save() {     return sc.Save(); }  public void ApplyAction() {     countEdit++;     Integer modolus = Math.mod(countEdit, 2);     String total = cv.HSE__c + cv.Professionalism_Integrity__c + cv.Quality_Accuracy__c + cv.Technology_Innovation__c + cv.Value_for_Money__c + cv.Timeliness__c;     if(modolus == 0)     {         readonly = false;         buttonValue = 'Save';     }     else     {         if(total != 'nullnullnullnullnullnull')            {         if (recordScan == 0){         insert cv;         readonly = true;         buttonValue = 'Edit';         }         else         {         update cv;         readonly = true;         buttonValue = 'Edit';         }         }     }    }   }  With this trigger.  trigger CoreValuesTrigger on Core_Values__c (before insert) {  Core_Values__c cvs = Trigger.new; CoreValuesExt.ApplyAction(cvs);  }   But when I try to save, I get a message saying:      Illegal assignment from List to   CoreValuesExt__Core_Values__c at line 3 column 1   "  How do I go through with this? I need help. Thanks