how to draw java chat Bubble speech? - java

hello for every one pls help me ,
i am trying to
make Java Desktop app for chatting
,i want to add chat representation in my chat application's to make UI style messages bubble speech Conversation so i want to draw by Java Code like this enter image description here pls help me the code or how to draw by java code like this ,
this my first post in https://stackoverflow.com/
Thank you

Judging from your question and your time here I take it that you are not too experienced with java (I mean no offence).
Instead you can do as I did, which worked perfectly fine for such a situation:
I created a JLabel, and assigned it an ImageIcon, In the code example below you will see me creating two labels which where to be used as buttons, one up and one down arrow for a list:
private void buildPair() {
//Make an ImageIcon Array (optional)
ImageIcon image[] = new ImageIcon[2];
//You create a new ImageIcon with the picture from your recouses, then you the the image and scale it, in this case its scaled to 20 by 20 pixel
Image originalDown = new ImageIcon(ExtendedList.class.getResource("/Elements/Down Arrow Button.png")).getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
Image originalUp = new ImageIcon(ExtendedList.class.getResource("/Elements/Up Arrow Button.png")).getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
//Then I add the scaled images to a new ImageIcon and then add it to my ImageIgon arrat
image[0] = new ImageIcon(originalDown);
image[1] = new ImageIcon(originalUp);
//Using an external Jlabel array i assing it with new Jlabel with this ImageIcon
buttonPair[0] = new JLabel(image[0]);
//I then add a custom event class, but you can make your own method or leave this out if its not needed
buttonPair[0].addMouseListener(events);
//And lastly i add this to my form
this.add(buttonPair[0]);
//and repeat for as many times as you need
buttonPair[1] = new JLabel(image[1]);
buttonPair[1].addMouseListener(events);
this.add(buttonPair[1]);
}
Do not forget to import:
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

Related

Resize and crop an image using ImageJ

I'm trying to resize and crop an image using ImageJ. Here's the code:
ImagePlus ip1 = IJ.openImage("_Pic.jpg");
ImagePlus ip2 = IJ.openImage("_Pic.jpg");
ImageProcessor imgP1 = ip1.getProcessor();
ImageProcessor imgP2 = ip2.getProcessor();
FileSaver fs1 = new FileSaver(ip1);
FileSaver fs2 = new FileSaver(ip2);
/* Trying to resize */
imgP1.resize(100); // also tried with width and height
fs1.saveAsJpeg("Resized.jpg");
/* Trying to crop */
imgP2.setRoi(100, 100, 200, 200);
imgP2.crop();
fs2.saveAsJpeg("Cropped.jpg");
Unfortunately, the newly created files are identical to the original one.
So far I've found out how to blur, smooth, invert, translate, rotate, ..., but these two are giving me hard time. Anybody has an idea?
Your cross-posted question to the ImageJ forum was answered there by Stefan Helfrich:
If you take a look at the Javadocs for ImageProcessor you'll see that resize() as well as crop() return new ImageProcessor instances and do not operate on this. That's why you'll have to use the ImagePlus.setProcessor(ImageProcessor) method to add the returned ImageProcessors to ip1 and ip2.
When cross-posting like this, please always include links to the other posts, so people finding this question later will have a chance to follow the discussion.
circle crop: https://youtu.be/OyiOFh1pD3k
resize: https://youtu.be/N_jddMMhzqc
combine both code.

I don't know why my image is not showing on the frame [duplicate]

This question already has answers here:
I took this code straight out of 'Java all in one for Dummies' ....why doesn't it work?
(2 answers)
Closed 8 years ago.
So, I do not know why my image is not showing because I put the image in the right folder and I believe that the code below is right. The result of this code is just a blank white frame background. I thought the image was corrupted but I tried a different image and its the same result. Anyway I will be highly grateful if anyone could solve this.
package fia_project;
import java.awt.Color;
java.awt.*;
import javax.swing.*;
public class Fia_test extends JFrame {
public Frame kenny;
public Fia_test(){
super("");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setVisible(true);
setSize(350, 100);
Container pane = getContentPane();
getContentPane().setBackground(Color.WHITE);
ImageIcon icon = new ImageIcon("speaker.png");
JLabel label2 = new JLabel(icon);
add(label2);
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Fia_test t = new Fia_test();
}
}
Use ImageIO.read instead of ImageIcon as it will generate an error if the image can not be loaded, much more useful for diagnostics. See Reading/Loading an Image
ImageIcon(String) expects that the specified String represents a file on the file system. From the looks of you code, it is possible that you've placed the image within the source directory of your code.
Assuming that the image has been bundled into the resulting Jar file, you will no longer be able to access the image as if it was a file on the file system, but will need to use Class#getResource to load it...
For example...
BufferedImage img = ImageIO.read(getClass().getResource("speaker.png"));
ImageIcon icon = new ImageIcon(img);
Assuming that speaker.png is in the same directory as the class file.

JFrame Icon Resolution

I'm quite new to working with java GUIs. To start me up, I had a look into JFrame. While playing around with it, I used the setIconImage() method to set the logo of my JFrame. However, when I run the file, the logo resolution gets reduced so much that I can barely recognise it. Here's my current code and the dimensions of my image is 1280 x 1280 (I have tried reducing it down to 100 x 100 but it still returned the same results.):
#SuppressWarnings("serial")
public class GUIManager extends JFrame{
public void openGUI(String value){
if(value.equalsIgnoreCase("startMenu")){
GUIManager manager = new GUIManager();
ImageIcon logo = new
ImageIcon(ResourcesLoader.class.getResource("Logo.png"));
manager.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
manager.setVisible(true);
manager.setResizable(false);
manager.setLocationRelativeTo(null);
manager.setSize(300, 500);
manager.setBackground(Color.WHITE);
manager.setTitle("FileLocker");
manager.setIconImage(logo.getImage());
} //value check
} //openGUI
} //GUIManager
The answer is given Before go to following link
Sizes of frame icons used in Swing
Which icon sizes to use with a JFrame's setIconImages() method?

Making a custom icon for a JFrame

Well I was wondering if I could make an icon image for a JFrame. I do know its posible, because, let me say, I am NOT digging the java logo.
Well if I just hava to use a Frame object I will.
Can someone tell me, I know its possible!
Use an ImageIcon.
ImageIcon icon = new ImageIcon( pathToIcon );
yourFrame.setIconImage(icon.getImage());
Good Luck!
First, you have to have an image file on your computer. It can be named anything. For this example, we will call this one "pic.jpg".
Next, you need to include it in the files that your application is using. For example, if you're using NetBeans, you simply click on "Files" in the left hand side of the IDE (not File as in the menu, mind you). Drag the picture's file over to the folder that houses the main package. This will include it for available use in the code.
Inside the method where you define the JFrame, you can create an image like this:
Image frameImage = new ImageIcon("pic.jpg").getImage();
You can now set it as the IconImage for the frame like this:
JFrame frame = new JFrame("Title");
frame.setIconImage(frameImage);
Hope that's helpful.
Note: the reason that the Image object has to be created like this is because Image is abstract and cannot be instantiated by saying new Image();
Props to you, btw, kid. I wish I would have started learning programming when I was your age. Keep at it!
You can do the following.
public Test {
public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.setIconImage(new ImageIcon(Test.class.getResource("image.png"));
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(true);
frame.setSize(100, 100);
//other stuffs....
}
}

Java User Interface: add simple chart

I am new to Java User Interface ..
I have my main window with a TabbedPane ...
I want to use a library of graphics to display ... I have chosen this and i looked this example ...
ChartExample
but, how can I add the example chart on my TabbedPane?
The chart API you have chosen generates charts using Google's API. This means you'll have to display the image from the URL of chart.toURLString(); in your app. This could be as simple as putting a JLabel on your tabbed pane and setting its caption to <img src="(url)"/>, but I'm not entirely sure that handles HTTP downloads.
JLabel label = new JLabel("<img src='" + chart.toURLString() + "'/>");
tabbedPane.add(label);
If it doesn't, you can use javax.ImageIO.read(URL) to load the chart image into a BufferedImage and then create a new ImageIcon to put that onto the label:
URL url = new URL(chart.toURLString());
BufferedImage bimg = ImageIO.read(url);
Icon icon = new ImageIcon(bimg);
JLabel label = new JLabel(icon);
tabbedPane.add(label);
Your application will need a live Internet connection for the chart image to show up. If you need the images to work when you have no Internet access, you'll have to use a different charting library such as JFreeChart.

Categories

Resources