current position:Home>How does Java cut and drag pictures onto the canvas
How does Java cut and drag pictures onto the canvas
2022-02-03 01:30:14 【CSDN Q & A】
I made one GUI, I'll put the picture below . Top left panel Can be used to generate images of existing data , Dexter panel Generate some pattern, Lower left corner panel It's the canvas .
)
Simply speaking , I can put the one on the right pattern Drag onto the lower left canvas , Then in other places of the drawing , I can continue drawing by myself .
【 This is a drag and drop process 】
【 Drag to canvas 】
【 Continue to draw on it by yourself 】
Now I hope I can do : For what I dragged down pattern, I can cut on the canvas , Put the selected part cut fall , Leave what I think is useful . But I don't know what to do here .
Because the interface itself is also left by a schoolgirl after she finishes , I just made some simple changes on it , But I really don't know how to do this part of drawing and dragging . Please help us to provide ideas .
I attach a part of the code .
JPanel leftDownPanel = new JPanel(); leftDownPanel.setBackground(Color.WHITE); leftDownPanel.setLayout(null); leftDownPanel.setBounds(10, 330, 720, 230); frame.getContentPane().add(leftDownPanel); frame.getContentPane().setBackground(new Color(252, 252, 252)); // add left down, up panel JPanel leftDownUpPanel = new JPanel(); leftDownUpPanel.setBackground(Color.WHITE); leftDownUpPanel.setLayout(null); leftDownUpPanel.setBounds(10, 0, 720, 30); leftDownPanel.add(leftDownUpPanel); JLabel drawLabel = new JLabel("Sketch"); drawLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); drawLabel.setBounds(10, 2, 120, 25); leftDownUpPanel.add(drawLabel); JButton clearButton = new JButton("Clear"); clearButton.setBounds(540, 2, 100, 25); clearButton.addActionListener(e -> { try { drawPanel.remove(0); leftDownChartPanel.repaint(); } catch (Exception e1) { e1.printStackTrace(); } drawPanel.repaint(); hasLeftDownChartPanel = false; series = new String[0]; doubles.clear(); dragTimes = 0; leftChartX = -1; }); leftDownUpPanel.add(clearButton); drawPanel = new JPanel(); drawPanel.setBounds(0, 28, 720, 200); drawPanel.setBackground(Color.WHITE); drawPanel.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseMoved(MouseEvent e) { x1 = e.getX(); y1 = e.getY(); } @Override public void mouseDragged(MouseEvent e) { Graphics graphics = drawPanel.getGraphics(); graphics.setColor(Color.BLUE); graphics.drawLine(x1, y1, e.getX(), e.getY()); x1 = e.getX(); y1 = e.getY(); doubles.add(1.5 - y1 * 0.01); size++; } }); leftDownPanel.add(drawPanel); } boolean hasLeftDownChartPanel = false; int dragTimes = 0; public void setLeftChart(int x, String[] series) { try { if (leftChartX == -1) { leftChartX = x; } System.out.println(x); System.out.println("=======Set Left Chart========="); dragTimes++; leftDownChartPanel = new Charts2().createChart(series); leftDownChartPanel.setMouseZoomable(false); JFreeChart chart = leftDownChartPanel.getChart(); CategoryPlot categoryPlot = chart.getCategoryPlot(); categoryPlot.setOutlineVisible(false); ValueAxis rangeAxis = categoryPlot.getRangeAxis(); CategoryAxis domainAxis = categoryPlot.getDomainAxis(); domainAxis.setVisible(false); rangeAxis.setVisible(false); leftDownChartPanel.setBackground(null); leftDownChartPanel.addMouseListener(new java.awt.event.MouseListener() { private int x; private int y; @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { if (e.isControlDown()) { this.x = e.getX(); this.y = e.getY(); } } @Override public void mouseReleased(MouseEvent e) { if (e.isControlDown()) { int xLen = e.getX() - x; int yLen = e.getY() - y; int startX = leftDownChartPanel.getX(); int half = leftDownChartPanel.getWidth() / 2; // left start part,expand if (Math.abs(xLen) > Math.abs(yLen)) { if (x < startX + half && e.getX() < x) { leftChartX = Math.max(leftChartX + xLen, 0); leftDownChartPanel.setBounds(leftChartX, 0, Math.min(Math.max(leftDownChartPanel.getWidth() + Math.abs(xLen), 100), 700), 150); System.out.println(1); } else if (x > startX + half && e.getX() < x) { leftDownChartPanel.setBounds(leftChartX, 0, Math.min(Math.max(leftDownChartPanel.getWidth() - Math.abs(xLen), 100), 700), 150); System.out.println(2); } else if (x < startX + half && e.getX() > x) { leftChartX = Math.max(leftChartX + xLen, 0); leftDownChartPanel.setBounds(leftChartX, 0, Math.min(Math.max(leftDownChartPanel.getWidth() - Math.abs(xLen), 100), 700), 150); System.out.println(3); } else if (x > startX + half && e.getX() > x) { // minus leftDownChartPanel.setBounds(leftChartX, 0, Math.min(Math.max(leftDownChartPanel.getWidth() + Math.abs(xLen), 100), 700), 150); System.out.println(4); } } else { leftDownChartPanel.setBounds(leftChartX, 0, leftDownChartPanel.getWidth(), Math.min(Math.max(leftDownChartPanel.getHeight() - yLen, 100), 250)); } leftDownChartPanel.repaint(); System.out.println("====xLen: " + xLen + "=====" + ", ====leftChartX: " + leftChartX + "======="); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); if (hasLeftDownChartPanel) { drawPanel.remove(0); } leftDownChartPanel.setBounds(leftChartX, 20, Math.min(180 * dragTimes, 600), 150); drawPanel.add(leftDownChartPanel, 0); drawPanel.repaint(); hasLeftDownChartPanel = true; } catch (Exception e) { e.printStackTrace(); } } int index = -1; boolean indexChange = false; JFrame jFrame = new JFrame(); int time = -1; MouseListener mouseListener = new MouseListener(); JLabel jLabel = new JLabel(); String[] series = new String[0]; private int leftChartX = -1; class MouseListener implements MouseInputListener { MouseListener() { jFrame.setUndecorated(true); jFrame.setBackground(new Color(0, 0, 0, 0)); jFrame.setLayout(null); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } @Override public void mouseReleased(MouseEvent e) { int x = jFrame.getX(); int y = jFrame.getY(); int x1 = drawPanel.getX() + drawPanel.getParent().getX() + frame.getX(); int y1 = drawPanel.getY() + drawPanel.getParent().getY() + frame.getY(); if (x1 <= x && x <= x1 + 600 && y1 <= y && y <= y1 + 270) { String[] series1 = datas2.get(index); int length = series.length + series1.length; String[] strings = new String[length]; System.arraycopy(series, 0, strings, 0, series.length); if (length - series.length >= 0) System.arraycopy(series1, 0, strings, series.length, length - series.length); series = strings; setLeftChart(x - x1, series); } jFrame.setBounds(10, 10, 10, 10); jFrame.setVisible(false); } @Override public void mousePressed(MouseEvent e) { if (index != e.getComponent().getY() / 180) { index = e.getComponent().getY() / 180; indexChange = true; } else { indexChange = false; } } @Override public void mouseExited(MouseEvent e) { frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } @Override public void mouseEntered(MouseEvent e) { frame.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); } @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseDragged(MouseEvent e) { time++; if (time > 0 && indexChange) { jFrame.remove(jLabel); jLabel = new JLabel(); } indexChange = false; jLabel.setIcon(labels[index].getIcon()); jLabel.setBounds(0, 0, labels[index].getWidth(), labels[index].getHeight()); Point location = frame.getLocation(); jFrame.setBounds((int) location.getX() + 500 + e.getX(), (int) location.getY() + 50 + index * 180 + e.getY() + jPanel.getY(), labels[index].getWidth(), labels[index].getHeight()); jFrame.getContentPane().add(jLabel); jFrame.repaint(); jFrame.setVisible(true); } @Override public void mouseMoved(MouseEvent e) { } }
Refer to the answer 1:
Tell the truth , Or ask questions without money ;
Or high price questions , You ask , So little money
It's hard to ..
Refer to the answer 2:
Refer to the answer 3:
Provide an idea about dragging :
stay pannel Define an area and select objects through mouse events , Also divide an area in your goal , Then replace the target object . learn delphi There are differences , I can't help you any more .
Refer to the answer 4:
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030130119330.html
The sidebar is recommended
- Why can't I see the absolute path of the command
- Pycharm uses the requests crawler to report the wrong requests exceptions. SSLError: HTTPSConnectionPool
- How to run multiple sleep () simultaneously in C language
- The data requested by Axios in vue3 is put into ecarts, which always shows that setoption is not defined
- What do these two for loops mean
- Java judges whether there are 30 consecutive int arrays with a length of 1000 as the growth trend
- Force deduction 221 question maximum square
- When I set this layout, I prompted an error from line 18
- The import javax. security. auth. message cannot be resolved
- The hottest Christmas tree code. one hundred and twenty-three
guess what you like
-
Open the edge browser and display "what if I can't access this page?"?
-
Running problems of java simple supermarket system
-
Is the data [10] here an address or an element? The concept is always unclear
-
Python crawling news content
-
How to deal with the problem of general code framework
-
Bubble sort, how can there be an extra number in front
-
The graph drawing algorithm of Python is described by Raptor flow chart software
-
Numpy creates an array of the specified data range
-
Python crawler obtains the data of Douban movie top250 fantasy class
-
R7-2 minimum spanning tree construction (25 points)
Random recommended
- Using burpsuite to capture the package of Pikachu shooting range SQL to inject the first level error
- Jar package conflict. I don't know where 2.29.1 came from
- About the rotation matrix on leetcode!
- The raspberry pie prompts cannot find webcams when running the command
- C + + a simple encryption, look at the warning how to modify, output nothing
- PHP composer and Vue node_ modules
- JDBC connects to the database for data deletion. The syntax is correct, but the data in the database cannot be deleted
- Java interface class program, define an interface and define two classes to implement the interface, then use the sorting method in the class, then enter an array with length of 8 in main, and call newsort with the two implementation classes as arguments
- Sort with average score, preferably bubble method
- When running the service jar, report Linux 1] + exit 1
- How to solve the problem of traceback? (Language Python)
- If an undirected graph G has 100 edges, how many vertices does the undirected graph have at least
- There was a problem calling the custom function
- The sum of a positive integer and 3 is a multiple of 5, and the difference between a positive integer and 3 is a multiple of 6. Write a program to find the minimum number that meets the conditions.
- Oracle has customized a date function. What's wrong with this writing?
- Spring boot project failed to introduce echarts
- How to solve this kind of program
- How to understand this? I didn't understand it at the beginning
- This problem requires the implementation of a function to reverse the given one-way linked list, that is, the header is set to the end of the table, and the end of the table is set to the header.
- *Isn't a numerical value? Because a is the address
- How should this program be completed
- The picture of U disk retrieved by app in Android 8.1 development board
- C language beginners' doubts, no, require recursion
- How to use bat or VBS to open Ethernet status window
- Base selection questions, C + + has just begun to learn, can someone give some ideas
- C language function problem,.?!
- Java class related problems
- What library is checkfasta in Python? Why can't you find it
- Problems encountered when deploying HTTPS certificates using docker nginx
- Why can't vs2022 run this code, but the compiler on the mobile phone can
- Java type conversion problem, is there a useful tool?
- C language function problem, confusion,.?!
- Please do me a favor and solve it
- Python learning has something you don't understand
- How does Baidu Post Bar get posts in it
- Who will prompt the board of STC89C52 if there is no professional course
- Can C language assign a value to the whole array
- How to prevent the page from sliding up and down when the wechat applet slides left and right
- Does anyone know why the information in this form can't come out? Hurry!
- Operation of strlen function