You may use Graphics.drawPolygon(int[], int[], int)
where the first int[] is the set of x values, the second int[] is the set of y values, and the int is the length of the array. (In a triangle’s case, the int is going to be 3)
Example:
graphics.drawPolygon(new int[] {10, 20, 30}, new int[] {100, 20, 100}, 3);
Output:
Related Posts:
- How do I draw a triangle?
- Adding JPanel to JFrame
- Java: Difference between the setPreferredSize() and setSize() methods in components
- Java GUI: about getContentPane( ) method and content
- How to add an image to a JPanel?
- How to repaint a JPanel after have drawn on it?
- addMouseListener for a JPanel
- Java Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
- How to programmatically close a JFrame
- How does addNotify() and requestFocus() work in Java with JPanel?
- Adding image to JFrame
- What does .pack() do?
- Setting background images in JFrame
- How to draw a circle with given X and Y coordinates as the middle spot of the circle?
- How change the color arrowIcon to JMenu when it is selected
- Getting a HeadlessException: No X11 DISPLAY variable was set
- error upon assigning Layout: BoxLayout can’t be shared
- Java: Rotating Images
- JOptionPane YES NO OPTION
- What does “AL lib: alc_cleanup: 1 device not closed” mean?
- How to center the text in a JLabel?
- Implementing an actionlistener to a JTextField
- How to Set JPanel’s Width and Height?
- Swing/Java: How to use the getText and setText string properly
- What does super.paintComponent(g) do?
- How to Set the Background Color of a JButton on the Mac OS
- Change the size of a JTextField inside a JBorderLayout
- Popup Message boxes
- Exception in thread “AWT-EventQueue-0”?
- make a JLabel wrap it’s text by setting a max width
- Keylistener not working for JPanel
- setMnemonic() and call a method by pressing the key
- the getSource() and getActionCommand()
- Java Error Exception in thread “AWT-EventQueue-0” java.lang.StackOverflowError
- DTO and DAO concepts and MVC
- How to Retrieve value from JTextField in Java Swing?
- Setting background color for a JFrame
- Java Swing revalidate() vs repaint()
- How does paintComponent work?
- How can I set size of a button?
- Java Swing setting JPanel Size
- JOptionPane Yes or No window
- How do I compare strings in Java?
- Could not reserve enough space for object heap
- What does “Could not find or load main class” mean?
- Exception in thread “main” java.util.NoSuchElementException
- “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G
- What’s the simplest way to print a Java array?
- javax vs java package
- What is a stack trace, and how can I use it to debug my application errors?
- How to fix “A JNI error has occurred, please check your installation.”
- Java optional parameters
- Java – Best way to print 2D array?
- How to update a value, given a key in a hashmap?
- How to schedule a periodic task in Java?
- typeof in Java 8
- Switch on Enum in Java
- What’s the difference between import java.util.*; and import java.util.stream;?
- Collections sort(List
,Comparator) method example - Login Application with 1 stage and multiple scene in JavaFX
- Handle mouse event anywhere with JavaFX
- restart console on Minecraft Server
- Type List vs type ArrayList in Java
- Maven error : Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
- Polymorphism vs Overriding vs Overloading
- Difference between Static methods and Instance methods
- Java The method is undefined for this type
- Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio
- Javamail Could not convert socket to TLS GMail
- java.net.SocketException: Connection reset
- Cannot instantiate the type Queue. Why is this?
- Pause the timer and then continue it
- Converting String Array to an Integer Array
- How to fix “unsupported class file major version 60” in IntelliJ?
- Hibernate Error: a different object with the same identifier value was already associated with the session
- How to solve the “failed to lazily initialize a collection of role” Hibernate exception
- Initializing multiple variables to the same value in Java
- Java: Unresolved compilation problem
- FXML Load exception
- NullPointerExcetion Native Method Accessor… Hashing Words Issue
- Static Initialization Blocks
- “Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar” when starting the Scala interpreter
- Get keys from HashMap in Java
- Determine if a String is an Integer in Java [duplicate]
- How do I run Java .class files?
- Fill an array with random numbers [duplicate]
- Connection Java – MySQL : Public Key Retrieval is not allowed
- Failed to install android-sdk: “java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema”
- Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven
- Regex pattern including all special characters
- Error: ‘)’ expected compiler error
- How to extract .war files in java? ZIP vs JAR
- when spring boot startup,throw out the “method names must be tokens” exception
- How to get javax.comm API?
- how to convert exe file to .jar file? [duplicate]
- How to print a table of information in Java
- set background color: Android
- Class Declarations for temperature program in Java
- Spring Boot – Cannot determine embedded database driver class for database type NONE
- Convert double to float in Java